linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: Stuart Hayhurst <stuart.a.hayhurst@gmail.com>,
	linux-input@vger.kernel.org
Cc: LKML <linux-kernel@vger.kernel.org>,
	Benjamin Tissoires <bentiss@kernel.org>,
	Jiri Kosina <jikos@kernel.org>
Subject: Re: [PATCH v2] HID: corsair-void: Add Corsair Void headset family driver
Date: Mon, 19 Aug 2024 09:48:15 +0200	[thread overview]
Message-ID: <bd07e14e-eae8-4264-b275-9efdf635cd82@web.de> (raw)
In-Reply-To: <20240818231940.34635-5-stuart.a.hayhurst@gmail.com>

…
> +++ b/drivers/hid/hid-corsair-void.c
> @@ -0,0 +1,857 @@
> +static ssize_t send_alert_store(struct device *dev,
> +				struct device_attribute *attr,
> +				const char *buf, size_t count)
> +{
> +	unsigned char *send_buf;

* How do you think about to use the attribute “__free(kfree)” at more places accordingly?
  https://elixir.bootlin.com/linux/v6.11-rc4/source/include/linux/slab.h#L282

* Would you like to reduce scopes for such local variables?

…
> +	if (!drvdata->connected)
> +		return -ENODEV;
> +
> +	if (drvdata->is_wired)
> +		return -ENODEV;
> +
> +	if (kstrtou8(buf, 10, &alert_id))
> +		return -EINVAL;
> +
> +	/* Only accept 0 or 1 for alert ID */
> +	if (alert_id >= 2)
> +		return -EINVAL;

Can condition checks be merged with the same return value (for less statements)?


> +	send_buf = kmalloc(3, GFP_KERNEL);

Can such a size determination be explained better?


…
> +	kfree(send_buf);
> +	return ret;
> +}
> +static void corsair_void_battery_add_work_handler(struct work_struct *work)
> +{
> +	struct corsair_void_drvdata *drvdata;
> +	drvdata->battery = power_supply_register(drvdata->dev,
> +						 &drvdata->battery_desc,
> +						 &psy_cfg);
> +
> +	if (IS_ERR(drvdata->battery)) {
> +		drvdata->battery = NULL;

I suggest to use another local variable for the previous return value
so that such a reset can be avoided.


> +		return;
> +	}
> +static DEVICE_ATTR_RO(fw_version_receiver);
> +static DEVICE_ATTR_RO(fw_version_headset);
> +static DEVICE_ATTR_RO(microphone_up);
> +static DEVICE_ATTR_RO(sidetone_max);
> +
> +static DEVICE_ATTR_WO(send_alert);
> +static DEVICE_ATTR_WO(set_sidetone);
> +
> +static struct attribute *corsair_void_attrs[] = {
> +};
> +
> +static const struct attribute_group corsair_void_attr_group = {
> +	.attrs = corsair_void_attrs,
> +};

Is there a need to organise device attributes into separate subgroups?


…
> +static int corsair_void_probe(struct hid_device *hid_dev,
> +			      const struct hid_device_id *hid_id)
> +{
> +	int ret = 0;

I propose to omit the explicit initialisation for this local variable.


> +	struct corsair_void_drvdata *drvdata;
> +	drvdata = devm_kzalloc(&hid_dev->dev, sizeof(struct corsair_void_drvdata),
> +			       GFP_KERNEL);

Please improve such a size determination.

See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.11-rc4#n953> +	goto success;

Please apply the statement “return 0;” instead.



> +/*failed_after_hid_start:
> +	hid_hw_stop(hid_dev);*/

Please reconsider the need once more also for this information.

Regards,
Markus

  reply	other threads:[~2024-08-19  7:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-18 23:19 [PATCH v2] HID: corsair-void: Add Corsair Void headset family driver Stuart Hayhurst
2024-08-19  7:48 ` Markus Elfring [this message]
2024-08-20  0:21   ` Stuart
2024-08-20  5:56     ` [v2] " Markus Elfring
2024-08-21  0:52       ` Stuart
2024-08-21  7:26         ` Markus Elfring
2024-08-21  9:52           ` Christophe JAILLET
2024-08-22  1:11             ` Stuart
2024-08-22  6:15               ` Christophe JAILLET
2024-08-22 11:57               ` Jiri Kosina
2024-08-22 15:36                 ` Stuart
2024-08-23  8:45         ` Markus Elfring

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=bd07e14e-eae8-4264-b275-9efdf635cd82@web.de \
    --to=markus.elfring@web.de \
    --cc=bentiss@kernel.org \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stuart.a.hayhurst@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).