Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Input: synaptics_i2c - switch to using managed resources

Switch the driver to use managed resources (devm_*) which simplifier
error handling and allows removing synaptics_i2c_remove() methods form
the driver.

Rename "ret" to "error" where makes sense while at it.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+90 -118
+90 -118
drivers/input/mouse/synaptics_i2c.c
··· 240 240 */ 241 241 static s32 synaptics_i2c_reg_get(struct i2c_client *client, u16 reg) 242 242 { 243 - int ret; 243 + int error; 244 244 245 - ret = i2c_smbus_write_byte_data(client, PAGE_SEL_REG, reg >> 8); 246 - if (ret == 0) 247 - ret = i2c_smbus_read_byte_data(client, reg & 0xff); 245 + error = i2c_smbus_write_byte_data(client, PAGE_SEL_REG, reg >> 8); 246 + if (error) 247 + return error; 248 248 249 - return ret; 249 + return i2c_smbus_read_byte_data(client, reg & 0xff); 250 250 } 251 251 252 252 static s32 synaptics_i2c_reg_set(struct i2c_client *client, u16 reg, u8 val) 253 253 { 254 - int ret; 254 + int error; 255 255 256 - ret = i2c_smbus_write_byte_data(client, PAGE_SEL_REG, reg >> 8); 257 - if (ret == 0) 258 - ret = i2c_smbus_write_byte_data(client, reg & 0xff, val); 256 + error = i2c_smbus_write_byte_data(client, PAGE_SEL_REG, reg >> 8); 257 + if (error) 258 + return error; 259 259 260 - return ret; 260 + error = i2c_smbus_write_byte_data(client, reg & 0xff, val); 261 + if (error) 262 + return error; 263 + 264 + return error; 261 265 } 262 266 263 267 static s32 synaptics_i2c_word_get(struct i2c_client *client, u16 reg) 264 268 { 265 - int ret; 269 + int error; 266 270 267 - ret = i2c_smbus_write_byte_data(client, PAGE_SEL_REG, reg >> 8); 268 - if (ret == 0) 269 - ret = i2c_smbus_read_word_data(client, reg & 0xff); 271 + error = i2c_smbus_write_byte_data(client, PAGE_SEL_REG, reg >> 8); 272 + if (error) 273 + return error; 270 274 271 - return ret; 275 + return i2c_smbus_read_word_data(client, reg & 0xff); 272 276 } 273 277 274 278 static int synaptics_i2c_config(struct i2c_client *client) 275 279 { 276 - int ret, control; 280 + int control; 281 + int error; 277 282 u8 int_en; 278 283 279 284 /* set Report Rate to Device Highest (>=80) and Sleep to normal */ 280 - ret = synaptics_i2c_reg_set(client, DEV_CONTROL_REG, 0xc1); 281 - if (ret) 282 - return ret; 285 + error = synaptics_i2c_reg_set(client, DEV_CONTROL_REG, 0xc1); 286 + if (error) 287 + return error; 283 288 284 289 /* set Interrupt Disable to Func20 / Enable to Func10) */ 285 290 int_en = (polling_req) ? 0 : INT_ENA_ABS_MSK | INT_ENA_REL_MSK; 286 - ret = synaptics_i2c_reg_set(client, INTERRUPT_EN_REG, int_en); 287 - if (ret) 288 - return ret; 291 + error = synaptics_i2c_reg_set(client, INTERRUPT_EN_REG, int_en); 292 + if (error) 293 + return error; 289 294 290 295 control = synaptics_i2c_reg_get(client, GENERAL_2D_CONTROL_REG); 291 296 /* No Deceleration */ ··· 299 294 control |= reduce_report ? 1 << REDUCE_REPORTING : 0; 300 295 /* No Filter */ 301 296 control |= no_filter ? 1 << NO_FILTER : 0; 302 - ret = synaptics_i2c_reg_set(client, GENERAL_2D_CONTROL_REG, control); 303 - if (ret) 304 - return ret; 297 + error = synaptics_i2c_reg_set(client, GENERAL_2D_CONTROL_REG, control); 298 + if (error) 299 + return error; 305 300 306 301 return 0; 307 302 } 308 303 309 304 static int synaptics_i2c_reset_config(struct i2c_client *client) 310 305 { 311 - int ret; 306 + int error; 312 307 313 308 /* Reset the Touchpad */ 314 - ret = synaptics_i2c_reg_set(client, DEV_COMMAND_REG, RESET_COMMAND); 315 - if (ret) { 309 + error = synaptics_i2c_reg_set(client, DEV_COMMAND_REG, RESET_COMMAND); 310 + if (error) { 316 311 dev_err(&client->dev, "Unable to reset device\n"); 317 - } else { 318 - usleep_range(SOFT_RESET_DELAY_US, SOFT_RESET_DELAY_US + 100); 319 - ret = synaptics_i2c_config(client); 320 - if (ret) 321 - dev_err(&client->dev, "Unable to config device\n"); 312 + return error; 322 313 } 323 314 324 - return ret; 315 + usleep_range(SOFT_RESET_DELAY_US, SOFT_RESET_DELAY_US + 100); 316 + error = synaptics_i2c_config(client); 317 + if (error) { 318 + dev_err(&client->dev, "Unable to config device\n"); 319 + return error; 320 + } 321 + 322 + return 0; 325 323 } 326 324 327 325 static int synaptics_i2c_check_error(struct i2c_client *client) 328 326 { 329 - int status, ret = 0; 327 + int status; 328 + int error; 330 329 331 330 status = i2c_smbus_read_byte_data(client, DEVICE_STATUS_REG) & 332 331 (CONFIGURED_MSK | ERROR_MSK); 333 332 334 - if (status != CONFIGURED_MSK) 335 - ret = synaptics_i2c_reset_config(client); 333 + if (status != CONFIGURED_MSK) { 334 + error = synaptics_i2c_reset_config(client); 335 + if (error) 336 + return error; 337 + } 336 338 337 - return ret; 339 + return 0; 338 340 } 339 341 340 342 static bool synaptics_i2c_get_input(struct synaptics_i2c *touch) ··· 433 421 delay = NO_DATA_SLEEP_MSECS; 434 422 } 435 423 return msecs_to_jiffies(delay); 436 - } else { 437 - delay = msecs_to_jiffies(THREAD_IRQ_SLEEP_MSECS); 438 - return round_jiffies_relative(delay); 439 424 } 425 + 426 + delay = msecs_to_jiffies(THREAD_IRQ_SLEEP_MSECS); 427 + return round_jiffies_relative(delay); 440 428 } 441 429 442 430 /* Work Handler */ ··· 466 454 static int synaptics_i2c_open(struct input_dev *input) 467 455 { 468 456 struct synaptics_i2c *touch = input_get_drvdata(input); 469 - int ret; 457 + int error; 470 458 471 - ret = synaptics_i2c_reset_config(touch->client); 472 - if (ret) 473 - return ret; 459 + error = synaptics_i2c_reset_config(touch->client); 460 + if (error) 461 + return error; 474 462 475 463 if (polling_req) 476 464 mod_delayed_work(system_dfl_wq, &touch->dwork, 477 - msecs_to_jiffies(NO_DATA_SLEEP_MSECS)); 465 + msecs_to_jiffies(NO_DATA_SLEEP_MSECS)); 478 466 479 467 return 0; 480 468 } ··· 501 489 input->id.bustype = BUS_I2C; 502 490 input->id.version = synaptics_i2c_word_get(touch->client, 503 491 INFO_QUERY_REG0); 504 - input->dev.parent = &touch->client->dev; 505 492 input->open = synaptics_i2c_open; 506 493 input->close = synaptics_i2c_close; 507 494 input_set_drvdata(input, touch); 508 495 509 496 /* Register the device as mouse */ 510 - __set_bit(EV_REL, input->evbit); 511 - __set_bit(REL_X, input->relbit); 512 - __set_bit(REL_Y, input->relbit); 497 + input_set_capability(input, EV_REL, REL_X); 498 + input_set_capability(input, EV_REL, REL_Y); 513 499 514 500 /* Register device's buttons and keys */ 515 - __set_bit(EV_KEY, input->evbit); 516 - __set_bit(BTN_LEFT, input->keybit); 501 + input_set_capability(input, EV_KEY, BTN_LEFT); 517 502 } 518 503 519 - static struct synaptics_i2c *synaptics_i2c_touch_create(struct i2c_client *client) 504 + static int synaptics_i2c_probe(struct i2c_client *client) 520 505 { 506 + struct device *dev = &client->dev; 521 507 struct synaptics_i2c *touch; 508 + int error; 522 509 523 - touch = kzalloc(sizeof(*touch), GFP_KERNEL); 510 + touch = devm_kzalloc(dev, sizeof(*touch), GFP_KERNEL); 524 511 if (!touch) 525 - return NULL; 512 + return -ENOMEM; 526 513 527 514 touch->client = client; 528 515 touch->no_decel_param = no_decel; ··· 529 518 set_scan_rate(touch, scan_rate); 530 519 INIT_DELAYED_WORK(&touch->dwork, synaptics_i2c_work_handler); 531 520 532 - return touch; 533 - } 521 + error = synaptics_i2c_reset_config(client); 522 + if (error) 523 + return error; 534 524 535 - static int synaptics_i2c_probe(struct i2c_client *client) 536 - { 537 - int ret; 538 - struct synaptics_i2c *touch; 539 - 540 - touch = synaptics_i2c_touch_create(client); 541 - if (!touch) 542 - return -ENOMEM; 543 - 544 - ret = synaptics_i2c_reset_config(client); 545 - if (ret) 546 - goto err_mem_free; 547 - 548 - if (client->irq < 1) 525 + if (client->irq <= 0) 549 526 polling_req = true; 550 527 551 - touch->input = input_allocate_device(); 552 - if (!touch->input) { 553 - ret = -ENOMEM; 554 - goto err_mem_free; 555 - } 528 + touch->input = devm_input_allocate_device(dev); 529 + if (!touch->input) 530 + return -ENOMEM; 556 531 557 532 synaptics_i2c_set_input_params(touch); 558 533 559 534 if (!polling_req) { 560 - dev_dbg(&touch->client->dev, 561 - "Requesting IRQ: %d\n", touch->client->irq); 535 + dev_dbg(dev, "Requesting IRQ: %d\n", client->irq); 562 536 563 - ret = request_irq(touch->client->irq, synaptics_i2c_irq, 564 - IRQ_TYPE_EDGE_FALLING, 565 - DRIVER_NAME, touch); 566 - if (ret) { 567 - dev_warn(&touch->client->dev, 568 - "IRQ request failed: %d, " 569 - "falling back to polling\n", ret); 537 + error = devm_request_irq(dev, client->irq, synaptics_i2c_irq, 538 + IRQ_TYPE_EDGE_FALLING, 539 + DRIVER_NAME, touch); 540 + if (error) { 541 + dev_warn(dev, "IRQ request failed: %d, falling back to polling\n", 542 + error); 570 543 polling_req = true; 571 - synaptics_i2c_reg_set(touch->client, 572 - INTERRUPT_EN_REG, 0); 544 + synaptics_i2c_reg_set(client, INTERRUPT_EN_REG, 0); 573 545 } 574 546 } 575 547 576 548 if (polling_req) 577 - dev_dbg(&touch->client->dev, 578 - "Using polling at rate: %d times/sec\n", scan_rate); 549 + dev_dbg(dev, "Using polling at rate: %d times/sec\n", scan_rate); 579 550 580 551 /* Register the device in input subsystem */ 581 - ret = input_register_device(touch->input); 582 - if (ret) { 583 - dev_err(&client->dev, 584 - "Input device register failed: %d\n", ret); 585 - goto err_input_free; 552 + error = input_register_device(touch->input); 553 + if (error) { 554 + dev_err(dev, "Input device register failed: %d\n", error); 555 + return error; 586 556 } 587 557 588 558 i2c_set_clientdata(client, touch); 589 559 590 560 return 0; 591 - 592 - err_input_free: 593 - input_free_device(touch->input); 594 - err_mem_free: 595 - kfree(touch); 596 - 597 - return ret; 598 - } 599 - 600 - static void synaptics_i2c_remove(struct i2c_client *client) 601 - { 602 - struct synaptics_i2c *touch = i2c_get_clientdata(client); 603 - 604 - if (!polling_req) 605 - free_irq(client->irq, touch); 606 - 607 - input_unregister_device(touch->input); 608 - kfree(touch); 609 561 } 610 562 611 563 static int synaptics_i2c_suspend(struct device *dev) ··· 586 612 587 613 static int synaptics_i2c_resume(struct device *dev) 588 614 { 589 - int ret; 590 615 struct i2c_client *client = to_i2c_client(dev); 591 616 struct synaptics_i2c *touch = i2c_get_clientdata(client); 592 617 struct input_dev *input = touch->input; 618 + int error; 593 619 594 - ret = synaptics_i2c_reset_config(client); 595 - if (ret) 596 - return ret; 620 + error = synaptics_i2c_reset_config(client); 621 + if (error) 622 + return error; 597 623 598 624 guard(mutex)(&input->mutex); 599 625 if (input_device_enabled(input)) ··· 628 654 }, 629 655 630 656 .probe = synaptics_i2c_probe, 631 - .remove = synaptics_i2c_remove, 632 - 633 657 .id_table = synaptics_i2c_id_table, 634 658 }; 635 659