Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp314448lqh; Sat, 4 May 2024 02:25:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUK2unfR7fcAzZj+1saFo8jSjmracfWTxGftsvAv1CPersi2fczSds2Vz8tuPKHKYyNHBsR1vr2E2lxs5Iri46JG/AknOkEOFk1keYL7A== X-Google-Smtp-Source: AGHT+IF90B/eh+aXEUdLsDYqh6eqXkDBp77VkTyuIGoddZhyRV5FgmB4xKsERrgq+OcKHH0skkY8 X-Received: by 2002:a05:620a:470e:b0:790:72c4:d5ea with SMTP id bs14-20020a05620a470e00b0079072c4d5eamr6719685qkb.25.1714814754402; Sat, 04 May 2024 02:25:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714814754; cv=pass; d=google.com; s=arc-20160816; b=vZJcddTQK/Al5ws95edWWJxxkBlrtQKJulgGbeY5zDhfaJQ+koLeNuet1EPlvbDM5s sTfj9BZOlsgfjnFfkqJ0wA0vZsXpIWzNqOzsxqgROpnkSnn/k8OVOHZKWLEck7ptw0Hb eIQa7cSM9lRBLqi9IuSFprQxCly6Ukza/GugxCcld6Bw/Yx9Y2PVSFC3C6LN1irEQopC vrClO2qfjxYtgJSFCXoc8WuXJmIgIa1bzTk141tj7ixW4TwHn13qOybpdfrH0QO5Chc+ EFGwkEY0s4pUntOTgHk2SL/oN7O+Iv0FwX7bo+CrQSipH6P8FQZDbufFf+T0S99ljKLT G4/w== 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:dkim-signature; bh=iVm0kTAiGaEirihJCdLOzEWROOpujxuN0/MjBFggZ0I=; fh=ljPGFPePkFZ/BVm4i7omzosDjfxc+Mf+IcfN5B5A6V4=; b=Cwf29bT96aNOxUD0TVxXNp/5NNepzZYjbLv1DbvLglylSvCtQKzQIzVbs3teMlf2cl hqlY3r6CjtroR799BT61dwWP9qP8iaFA7/f0VZy47Z5K0/ZBk2OMz9sWUWrt1J3+VMiC 5wX7vrMeeI0t2k+xHO7es3rtSBcP5+zLV8WlJ7SrOC+tzR/fW/yMRcZV8bghsfShB9Cs GfNDppqW3NS6LBecj4nUwnGy0Jk6cT6xbQnQBxqFrSeQ7V1JfFgGxpXMNE3VuvQUFe/8 l1XighQdlZDJEfPHc/dVAORKt+uXYfT/kOufrl0btWIDX06J3/hxtidSF8G3RI+qXSgJ Xd5w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Mzy6H4hR; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-168567-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168567-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d14-20020a05620a136e00b007928fe09c63si72291qkl.785.2024.05.04.02.25.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 02:25:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-168567-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; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Mzy6H4hR; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-168567-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168567-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 274B31C21104 for ; Sat, 4 May 2024 09:25:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 888E9182CC; Sat, 4 May 2024 09:25:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Mzy6H4hR" Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 115CC171AB; Sat, 4 May 2024 09:25:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714814736; cv=none; b=SEHQyAjE0QTU3MgBCuZToWWHiEIqNo1qt1DbDiKZgViBqPi6tdp0dHzet/mDf5Iws55AIQCYcm5WP2m2SoI/w/OHqMzK64XDVP4UEUP0FNze3j1D+rQYZF8YVqjr8tCeUHqk5c/Zz+KzLgHZHHQIsEIbf++c97LDuuiLNQKU/4E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714814736; c=relaxed/simple; bh=lgWGaO6LzlXcstlxO7ac8VqYmC+yW7DzTwsyoRKraBs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GQvjchf+UjejEJbmmSn3rH3rKmQ7EK/GExK3MA7kVywvrh77mp77Ym5Tw+gqiLoNjQiEXn1eXI3peYujcGKv5JqYVFsbEaU1kE9FaXa4COUqVJ8QQAcyKZxZAg36mce1MOI9WmpFvR4Q8COxpKjIA/vfvpLRLqU569RfvJUlY4U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Mzy6H4hR; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a599a298990so85788166b.2; Sat, 04 May 2024 02:25:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714814732; x=1715419532; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iVm0kTAiGaEirihJCdLOzEWROOpujxuN0/MjBFggZ0I=; b=Mzy6H4hRGV5+1zzsHQ/Lrqxw9DSr/Kyj4ktC0iqIPEi9zEpzzY1sFXYGLFJT63Ypyq e4CZeKjp+b6mAdMYBW3O2Q1dSGdDnjX6bcMXoSm1zqZld7/0Q3z4CX1YGcvyZjcXetuv JwKlTkzWeHDpogB6sORSpXJ37+wEJ+qQ3FJ+jTN0Phnx3UBOWuPWY4uQUZxixl9kyOLU CqGBmAzCSTGWiS91stfo67roAEttcrnsF3UumF7xoZ3kC3GuKfwJ5gbccHib48w58PrP geVFtqTfDpkOKMS5HB/PwWzr891rU55DyWov3NNkhtrYze0XJCvRnNZhLs1PpkpiU0oX l1Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714814732; x=1715419532; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iVm0kTAiGaEirihJCdLOzEWROOpujxuN0/MjBFggZ0I=; b=Vtsh8IPqwRW2vZW9mA/mM8RpsiZZwr4hwe8w+hIWl7UtGOa45dhxv3tZjqYy1zE8d6 UQzR9Pwwbk3B7I4lbhOr0DSGV3ahwDoUcDj+ImktXg+etg+DSVZpUrIZDLCCIthj/YST Tl36JYbZHZV53gbTDxLntMjDk12lI1GDBNmfs6NzeK+ecQ1LV66yhPE8DchwT6hDzWA5 huz047IM9aC9acMuX4TLRoJz+uDNKmK1AVpVLI1ubgelSWGo2AdSRzMmUmNqgeoxz8+u 8iherks/HEDE8Rt+Bl3DQH7YejFv1+Sww0EcfaURGqQy7UkO1p4qsQHKBXnKtWPoPoO8 oRqg== X-Forwarded-Encrypted: i=1; AJvYcCXlHT/3uv6CfxGXIUDBblBMd6mAPs4aUDjs0sd3cCBNFZJoc1S7bkLY4EVSPUX5l+uQVO4o2mtWKEZ33UfJqMJSHfCiASQTgSj2nBoa X-Gm-Message-State: AOJu0Yy6nQRe8EL04o++xjpQ3ycJkt5dPqNSq/R9Q0WdU21mYbOguHEI hWobTN9wkB72bGPFJHz5CklXsIxVUbt2YP0az3jElu4zqobdrYJlxBo7MfPWNGM= X-Received: by 2002:a17:906:a145:b0:a58:832d:c3e8 with SMTP id bu5-20020a170906a14500b00a58832dc3e8mr3248087ejb.58.1714814732249; Sat, 04 May 2024 02:25:32 -0700 (PDT) Received: from fedora.. (cable-178-148-234-71.dynamic.sbb.rs. [178.148.234.71]) by smtp.gmail.com with ESMTPSA id ce3-20020a170906b24300b00a587831c09fsm2740231ejb.186.2024.05.04.02.25.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 02:25:31 -0700 (PDT) From: Aleksa Savic To: linux-hwmon@vger.kernel.org Cc: Jonas Malaco , Aleksa Savic , Marius Zachmann , Jean Delvare , Guenter Roeck , linux-kernel@vger.kernel.org Subject: [PATCH 1/3] hwmon: (corsair-cpro) Use a separate buffer for sending commands Date: Sat, 4 May 2024 11:25:01 +0200 Message-ID: <20240504092504.24158-2-savicaleksa83@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240504092504.24158-1-savicaleksa83@gmail.com> References: <20240504092504.24158-1-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: 8bit 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; -- 2.44.0