public inbox for linux-input@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: Angela Czubak <aczubak@google.com>
Cc: linux-input@vger.kernel.org
Subject: [bug report] HID: haptic: initialize haptic device
Date: Thu, 18 Sep 2025 10:18:38 +0300	[thread overview]
Message-ID: <aMuyTgPtUnfdk091@stanley.mountain> (raw)

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

             reply	other threads:[~2025-09-18  7:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-18  7:18 Dan Carpenter [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-09-18  9:46 [bug report] HID: haptic: initialize haptic device Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aMuyTgPtUnfdk091@stanley.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=aczubak@google.com \
    --cc=linux-input@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox