[bug report] HID: haptic: initialize haptic device
From: Dan Carpenter <hidden>
Date: 2025-09-18 07:18:44
Hello Angela Czubak,
Commit 344ff3584957 ("HID: haptic: initialize haptic device") from
Aug 18, 2025 (linux-next), leads to the following Smatch static
checker warning:
drivers/hid/hid-haptic.c:528 hid_haptic_init()
warn: missing error code here? '_dev_err()' failed. 'ret' = '0'
drivers/hid/hid-haptic.c
518 }
519
520 ff = dev->ff;
521 ff->private = haptic;
522 ff->upload = hid_haptic_upload_effect;
523 ff->playback = hid_haptic_playback;
524 ff->erase = hid_haptic_erase;
525 ff->destroy = hid_haptic_destroy;
526 if (!try_module_get(THIS_MODULE)) {
527 dev_err(&hdev->dev, "Failed to increase module count.\n");
--> 528 goto input_free;
Missing error code. I think we're trying to pump the module count so
this module is unloadable. That's a discouraged thing so the
__module_get() function has a double underscore. But here we're kind
of dressing it up so it looks like we're doing a legit module count
bump of a different module that we rely on (instead of THIS_MODULE). We
should just use __module_get() because it's more honest and remove the
check.
529 }
530 if (!get_device(&hdev->dev)) {
531 dev_err(&hdev->dev, "Failed to get hdev device.\n");
532 module_put(THIS_MODULE);
533 goto input_free;
Missing error code, but get_device() can't really fail here. Just remove
the check.
534 }
535 return 0;
536
537 input_free:
538 input_ff_destroy(dev);
539 /* Do not let double free happen, input_ff_destroy will call
540 * hid_haptic_destroy.
541 */
542 *haptic_ptr = NULL;
543 /* Restore dev flush and event */
544 dev->flush = flush;
545 dev->event = event;
546 return ret;
547 stop_buffer_free:
548 kfree(haptic->stop_effect.report_buf);
549 haptic->stop_effect.report_buf = NULL;
550 buffer_free:
551 while (--r >= 0)
552 kfree(haptic->effect[r].report_buf);
553 kfree(haptic->effect);
554 haptic->effect = NULL;
555 output_queue:
556 destroy_workqueue(haptic->wq);
557 haptic->wq = NULL;
558 duration_map:
559 kfree(haptic->duration_map);
560 haptic->duration_map = NULL;
561 usage_map:
562 kfree(haptic->hid_usage_map);
563 haptic->hid_usage_map = NULL;
564 exit:
565 return ret;
566 }
regards,
dan carpenter