From: Marius Zachmann <mail@mariuszachmann.de>
To: linux-hwmon@vger.kernel.org, Aleksa Savic <savicaleksa83@gmail.com>
Cc: Jonas Malaco <jonas@protocubo.io>,
Aleksa Savic <savicaleksa83@gmail.com>,
Jean Delvare <jdelvare@suse.com>,
Guenter Roeck <linux@roeck-us.net>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] hwmon: (corsair-cpro) Use a separate buffer for sending commands
Date: Sat, 04 May 2024 14:14:18 +0200 [thread overview]
Message-ID: <6041245.lOV4Wx5bFT@marius> (raw)
In-Reply-To: <20240504092504.24158-2-savicaleksa83@gmail.com>
On 04.05.24 at 11:25:01 MESZ, Aleksa Savic wrote
> Introduce cmd_buffer, a separate buffer for storing only
> the command that is sent to the device. Before this separation,
> the existing buffer was shared for both the command and the
> report received in ccp_raw_event(), which was copied into it.
>
> However, because of hidraw, the raw event parsing may be triggered
> in the middle of sending a command, resulting in outputting gibberish
> to the device. Using a separate buffer resolves this.
>
> Fixes: 40c3a4454225 ("hwmon: add Corsair Commander Pro driver")
> Signed-off-by: Aleksa Savic <savicaleksa83@gmail.com>
> ---
> drivers/hwmon/corsair-cpro.c | 19 ++++++++++++-------
> 1 file changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/hwmon/corsair-cpro.c b/drivers/hwmon/corsair-cpro.c
> index a284a02839fb..8d85f66f8143 100644
> --- a/drivers/hwmon/corsair-cpro.c
> +++ b/drivers/hwmon/corsair-cpro.c
> @@ -79,6 +79,7 @@ struct ccp_device {
> struct device *hwmon_dev;
> struct completion wait_input_report;
> struct mutex mutex; /* whenever buffer is used, lock before send_usb_cmd */
> + u8 *cmd_buffer;
> u8 *buffer;
> int target[6];
> DECLARE_BITMAP(temp_cnct, NUM_TEMP_SENSORS);
> @@ -111,15 +112,15 @@ static int send_usb_cmd(struct ccp_device *ccp, u8 command, u8 byte1, u8 byte2,
> unsigned long t;
> int ret;
>
> - memset(ccp->buffer, 0x00, OUT_BUFFER_SIZE);
> - ccp->buffer[0] = command;
> - ccp->buffer[1] = byte1;
> - ccp->buffer[2] = byte2;
> - ccp->buffer[3] = byte3;
> + memset(ccp->cmd_buffer, 0x00, OUT_BUFFER_SIZE);
> + ccp->cmd_buffer[0] = command;
> + ccp->cmd_buffer[1] = byte1;
> + ccp->cmd_buffer[2] = byte2;
> + ccp->cmd_buffer[3] = byte3;
>
> reinit_completion(&ccp->wait_input_report);
>
> - ret = hid_hw_output_report(ccp->hdev, ccp->buffer, OUT_BUFFER_SIZE);
> + ret = hid_hw_output_report(ccp->hdev, ccp->cmd_buffer, OUT_BUFFER_SIZE);
> if (ret < 0)
> return ret;
>
> @@ -492,7 +493,11 @@ static int ccp_probe(struct hid_device *hdev, const struct hid_device_id *id)
> if (!ccp)
> return -ENOMEM;
>
> - ccp->buffer = devm_kmalloc(&hdev->dev, OUT_BUFFER_SIZE, GFP_KERNEL);
> + ccp->cmd_buffer = devm_kmalloc(&hdev->dev, OUT_BUFFER_SIZE, GFP_KERNEL);
> + if (!ccp->cmd_buffer)
> + return -ENOMEM;
> +
> + ccp->buffer = devm_kmalloc(&hdev->dev, IN_BUFFER_SIZE, GFP_KERNEL);
> if (!ccp->buffer)
> return -ENOMEM;
>
>
Thank you!
Acked-by: Marius Zachmann <mail@mariuszachmann.de>
next prev parent reply other threads:[~2024-05-04 12:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-04 9:25 [PATCH 0/3] hwmon: (corsair-cpro) Fix issues when hidraw is used Aleksa Savic
2024-05-04 9:25 ` [PATCH 1/3] hwmon: (corsair-cpro) Use a separate buffer for sending commands Aleksa Savic
2024-05-04 12:14 ` Marius Zachmann [this message]
2024-05-04 9:25 ` [PATCH 2/3] hwmon: (corsair-cpro) Use complete_all() instead of complete() in ccp_raw_event() Aleksa Savic
2024-05-04 12:14 ` Marius Zachmann
2024-05-04 9:25 ` [PATCH 3/3] hwmon: (corsair-cpro) Protect ccp->wait_input_report with a spinlock Aleksa Savic
2024-05-04 12:14 ` Marius Zachmann
2024-05-04 13:37 ` [PATCH 0/3] hwmon: (corsair-cpro) Fix issues when hidraw is used Guenter Roeck
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=6041245.lOV4Wx5bFT@marius \
--to=mail@mariuszachmann.de \
--cc=jdelvare@suse.com \
--cc=jonas@protocubo.io \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=savicaleksa83@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.