Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp380046lqh; Sat, 4 May 2024 05:18:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXuBRkI123aoHKmgtP/cU5hoeU0SfwZooc7TeoZeqrK+rJjzCdNBZ2x/q1fNiorIk5JqKHTGxeTavu7ipwLgYmPVkL3Ud8N+85GZ8i60A== X-Google-Smtp-Source: AGHT+IGWnN6k4qmTwJBdMARjOTaSNM6e5un+DrvVgqaWaV+EMOsq9801zRfY4qumCyF1vnOLJFYl X-Received: by 2002:a05:620a:2441:b0:790:f42f:cdbe with SMTP id h1-20020a05620a244100b00790f42fcdbemr6942999qkn.9.1714825103154; Sat, 04 May 2024 05:18:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714825103; cv=pass; d=google.com; s=arc-20160816; b=FYovX3SOCgjEOSHmTSWiybwkLE7//QQRMkuXJD20WXZmic6K1+GJzH17/DIykqVayu NAFi9mK47Jej3wZ9sRv9sq1r9IPYyNOn3wsrQkuX/AeWdk2wWsbpPrkDpTWk/lo3gvHK eH/jp3ANWb8hct/ZWQsC3BdgVPSakLZ9mDjuUR3A4UfEGEeEjizJcSYQa6M59FIu6cbs BljDsv0c3V1aBO3mOpA9pQPb6O28/2pM7VXHhqUJrcL6GR4oCDZ2tQYRdPf7tfEcY3DR E3I20mVU6dRoSSnpPYIJEEJw22MFfvG0L0RDfXbfMLrLUc1vV1mAiDjtKZ/416k/eB1I YXlg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=DTOU329SMgjk8TQYLCPrRjhqbavBpMjpugLm3sEtSgA=; fh=KXdso3hycph+C6tqeso+YqAvEeCzYtD89ujQtxlmfTg=; b=QYp5aoAwfPgulw2ZGtNhhE4kMG4mJOINgM/gw2hGG6mWaioM9aWX4FQAuF/zF+cMYp t4aZKQ5Hsf20s7cX9uE1REjTG9IyH33pbwzQNooI5rzx889hxTETCCH0fcbamTrGft/j V0qRCjRDfNRn+TQGRkcu0MCpzljtg1HKiDh+1ovDVTRDroqsmfYNtLw/0kG8JuYfIqb0 CE8IoYQ2HJuPiEL2NIG9ih7TfG935Uf0QDEeX8wVDz3RO/TYmj5+z/VTh7E8tfJf9NMq UmoZDVypREUwfcL+65Q2kvZihXQho2iDOPDOJ13IgZ6YsZH+3RR+tzNZdfQ+gmpWIFxz eCng==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=mariuszachmann.de); spf=pass (google.com: domain of linux-kernel+bounces-168641-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168641-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id h12-20020ae9ec0c000000b00790f9caef16si4896247qkg.568.2024.05.04.05.18.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:18:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-168641-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=mariuszachmann.de); spf=pass (google.com: domain of linux-kernel+bounces-168641-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168641-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DBC9D1C211B1 for ; Sat, 4 May 2024 12:18:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B6D4D21342; Sat, 4 May 2024 12:18:17 +0000 (UTC) Received: from ms-10.1blu.de (ms-10.1blu.de [178.254.4.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 964B05234; Sat, 4 May 2024 12:18:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.254.4.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714825097; cv=none; b=o+9I3LGfflJ5FXbSTK95CPc4x6KmU9lCaLDf6PL++8nEiJZovgMg27zLLZvXqrfHI0bbUsgx4DBXbk8XZD+2CYuvsxTh6iPtrGAf8koDVhsROtNlST9ioo0BQGHviS2uWXhPc/9oRdth83/TLQl+Gr6Eh7fRBHg0i9ve1cCp1Ug= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714825097; c=relaxed/simple; bh=CsIZ8ETxiJAGv+CnlYM534fFITb1mczKbTdqGZHPBfY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nzcqIEHByDVKV7G18LBTpyWBpnxWNQsBUhs6YcTZ1w8NI+p2fA8uAJYsS1qnC6jK7hOMN5Dvx+wHiYpSivMIDjsvnSmEGFD1Wng34RAreTWUQlL7icB+AHoW+J90CLPMwhAt+UlpGgEw7BRrYrazdMzxOYOPi3ZLWRTsPd0GBgY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mariuszachmann.de; spf=pass smtp.mailfrom=mariuszachmann.de; arc=none smtp.client-ip=178.254.4.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mariuszachmann.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mariuszachmann.de Received: from [2.211.228.80] (helo=marius.localnet) by ms-10.1blu.de with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1s3EHT-00FLNS-C6; Sat, 04 May 2024 14:14:19 +0200 From: Marius Zachmann To: linux-hwmon@vger.kernel.org, Aleksa Savic Cc: Jonas Malaco , Aleksa Savic , Jean Delvare , Guenter Roeck , 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 Message-ID: <6041245.lOV4Wx5bFT@marius> In-Reply-To: <20240504092504.24158-2-savicaleksa83@gmail.com> References: <20240504092504.24158-1-savicaleksa83@gmail.com> <20240504092504.24158-2-savicaleksa83@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" X-Con-Id: 241080 X-Con-U: 0-mail 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 > --- > 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