From patchwork Tue Dec 13 14:04:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Sven_Z=C3=BChlsdorf?= X-Patchwork-Id: 13072095 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35ADCC10F1D for ; Tue, 13 Dec 2022 14:05:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229803AbiLMOFG (ORCPT ); Tue, 13 Dec 2022 09:05:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229787AbiLMOFE (ORCPT ); Tue, 13 Dec 2022 09:05:04 -0500 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2064.outbound.protection.outlook.com [40.107.104.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61CE0634B; Tue, 13 Dec 2022 06:05:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MAaH39G3xuqnUOEVy0sqMD1fDjtb97Oie70HUzhN7d5nnMO+63u2OsSm7A07haVW91QhE7e6JQoUIdUcw0kiMcLCogl30XQ+/rdIpIfijBaZ4q5EHVMcTFPQAF6MMyD686eTAZh9hZewtLJU23ARJTIsxMfDgJtixjGgqMOJ2xOR9Dve5c/k5GQ6vJfXHsLAlJvJ12G9WO9BJTuNd6eWDiGrw/l6zRNBla0VzZJdYvSAyv1K4AzRLu/3WI7tSLfNAPzbnGIlLfyrZbWLlYZcTHcJw4VK8R8SiW3uuSnJSKfc3hWnkrk1QFXqZXanKShL3SRPnIrv8HaBP2d2irUyaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+GtkjTxN5cDQ4ou9RHv6Ceh1CDyQGaQ4mGN7Q76yGpY=; b=nJLsjNAj13SqoF9kjXgWAg9WpagtQTiV0OHYrF75bxDzuQ0TAuSjY5xiO7ENYlnnQUbwfM+UbUZINoffVbVM86at+81iJV9nrom6fSBOKVjR+rdl7TDKDNpNaJjvrUkccZjbyFidByBX2DYDW/+BT7uN6NIEbrGxIpG3Gb6TJsdLaTNu1NbSaNwC1J5fNd/Wp6i5xm6bAc8CRxOPP/7MtqtwY4DNy1YaVAymyIAuHofUpYVSN2r7nnCGjfLYPPCxd9a1KQdyDB4N8doBrviaZS0ZQTgSrrXBz/wZfxUm6Htw3s29Ggwf655asaV2U8HgQi2m6d0FiJuI0NBJNRYbjA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vigem.de; dmarc=pass action=none header.from=vigem.de; dkim=pass header.d=vigem.de; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vigem.de; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+GtkjTxN5cDQ4ou9RHv6Ceh1CDyQGaQ4mGN7Q76yGpY=; b=ka3VDLt8c8YUgCOAPNv2e/7+NlJNE7DyONZmC/AgTGXNQWO3LFtK0PVyOGKalyKecRCyxgtdJSSkcPvSujpvreHd1kkuGew9rQF/uomVnZXQadRcUvgU7xLE1EYcV9PH0BC0DhDxHvlSO0cLQCZZWkNJiWOqW1Fmn2dsBAI4GuE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vigem.de; Received: from DU0P190MB1930.EURP190.PROD.OUTLOOK.COM (2603:10a6:10:3bd::20) by DB9P190MB1843.EURP190.PROD.OUTLOOK.COM (2603:10a6:10:37e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.19; Tue, 13 Dec 2022 14:04:59 +0000 Received: from DU0P190MB1930.EURP190.PROD.OUTLOOK.COM ([fe80::ece:ddee:45dd:492]) by DU0P190MB1930.EURP190.PROD.OUTLOOK.COM ([fe80::ece:ddee:45dd:492%4]) with mapi id 15.20.5880.019; Tue, 13 Dec 2022 14:04:59 +0000 Date: Tue, 13 Dec 2022 15:04:57 +0100 (CET) From: =?utf-8?q?Sven_Z=C3=BChlsdorf?= To: Rishi Gupta cc: Randy Dunlap , Benjamin Tissoires , Enrik Berkhan , linux-input@vger.kernel.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] HID: mcp2221: fix probing of the I2C bus added by hid_mcp2221 Message-ID: <55d7a712-5862-4d51-9ec8-7479dce15f78@vigem.de> X-ClientProxiedBy: FR3P281CA0192.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a4::16) To DU0P190MB1930.EURP190.PROD.OUTLOOK.COM (2603:10a6:10:3bd::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0P190MB1930:EE_|DB9P190MB1843:EE_ X-MS-Office365-Filtering-Correlation-Id: 5096fa8b-e5f6-44ed-c2f2-08dadd130518 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Evbv/K0QaO6a10HYMXGEHq3rvacSWDRoPc4PhgnCFjXUmMACkWml8Hl57NNxLm0cSnrzefTAliVD8RC+WCcl2SD0gCQsxSYMQvSO1cCHXj5sOcN50Ti1qMObXJO7BSdTjtA7L2l30kpefTKJlS9jAz60jD/IebJUbuXxygzW2jwlVtEppNXdvCp4ZiNLkqDeBrUTRi7qGENCT+rfIw5DeHW3HIDPUCPVy5cMErs1DkRrsU0fNcCQp0OSssuXPMm36k6SNoFZmjrsarPwbFK3/U3+4OLWN6KVdo89OI3UoFRvzgutGCrfUBO8D+F2bmKRcVXP97gbm2YbZJhLF9kD4EQTgyhj8xE9kiXdFUAquUyFs9K7z3mABeDL53UrDGpxu/UXssYr4HxBK+tDprTlXVRouiVw6Ug0vUDl+C6N34vtqVYG4SeTcMJx946vSvvjddu13ddH5vO7D+MyvfJS1zVZE6GPA1Mb0Bfb+DdJFVz2gE8SmQehRx5l5z9XomvldrcKwsayCKa6A6Cw60c5DYvwQ5IRbamgI/t7/AAR7M9gKpX/cADYdpFO0Dsuov/+t/vZpFnuB0Smwp3J96rxHfILjgWDltzXjjp+/TSRrok7E1zUrZgFIH/YCGhn1R+eoB8C1XQPMcONwwoFrwCAa20pgqKCNI8CEB3gJILQo3HUx4zO0NfTdkF8fJJ1NwVZmBoJYJNNBlBAbNuNKveYB9+vD2fHGA3bZ5GJuIJ7538= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU0P190MB1930.EURP190.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230022)(4636009)(136003)(376002)(366004)(346002)(39840400004)(396003)(451199015)(38350700002)(31686004)(5660300002)(33964004)(6506007)(26005)(86362001)(31696002)(2906002)(41300700001)(36756003)(52116002)(8936002)(66556008)(8676002)(66946007)(316002)(66476007)(4326008)(38100700002)(478600001)(186003)(83380400001)(6486002)(53546011)(66574015)(6512007)(54906003)(6916009)(2616005)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?RTP/gynmWUAXZZzKZ4u1dM/Miizk?= =?utf-8?q?dZe+ZWD5vH4IUATE2j82LtSy5WcgvQ1Zs0Y51WlucnbMiwrYtbJXClFHRIeyDhZ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7IDT+Oc9NPF/?= =?utf-8?q?/qrMdbq6yzw286TSh1HnhbhfGJG8ZMlLu46Y5nFcnR2MS24pQIMgPxDO8tCk8TGzC?= =?utf-8?q?ip1YFZhXEYgnC0OxKro7T/hQbYOvplJ+1tC4tkG/vDuMKdKuwr+XdSyD8CymZYZZJ?= =?utf-8?q?g9C+94bBusZ6s8MR0vmeqcXg4hwKebJZPQjtl4MjxgDyam96BjcSqVpXFfSNHo395?= =?utf-8?q?nyIaDyfL3BiFqXAisHk7baKlC1DRwcvgAy6klTwyGPqgTwGmtjklLJGSjTEh2d3Np?= =?utf-8?q?yo+TopvaqjSkyKqDxUz5aJduMjZCDEzjkILFiPU43IM9uK4JV+E8Xl4RW0zVe5++w?= =?utf-8?q?sEppXIHq+w83JLnLrv4M5Ctcpzdz98H9o+H3uSN6hAoDqiqFgKtkNAEJzs4hdm6VS?= =?utf-8?q?IN9bMLUfKalGXpTJAyC62eWgi+hzQbXh7lajd/nurNR6rQl6wWVNodHMw9fbEgn3o?= =?utf-8?q?WTjMsSAFjEYayT96yWRcDsTCjiEtuJC4UcFnWWoF+MhkCYMuUTg0ZvDJijnyiuhls?= =?utf-8?q?he9BgMFsEWNwgqhvHUHLPufiyD5QCmg8ejs3Sjy3j+OlCY/tgr6xi5efKyftt5Ws3?= =?utf-8?q?fBFJ/1y+AD6g8pHIHL43OUY+MN5tA4VCUA=3D=3D?= X-OriginatorOrg: vigem.de X-MS-Exchange-CrossTenant-Network-Message-Id: 5096fa8b-e5f6-44ed-c2f2-08dadd130518 X-MS-Exchange-CrossTenant-AuthSource: DU0P190MB1930.EURP190.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Dec 2022 14:04:58.9253 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: dc3cc44e-876e-4b98-9250-42df44be4933 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RqAflhm7f/9ynpncF9nSUAJfbyL6l3FJWUcPcbNCsqG0qxOE3rGaAAaEKyNGomE0gBHnHcWyBeJ/b1WdiZK8CODiuuQ+TYGJ7RSIQr2MXC8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9P190MB1843 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Karl Georg Esser Date: Fri, 9 Dec 2022 16:17:59 +0100 Subject: [PATCH] HID: mcp2221: fix probing of the I2C bus added by hid_mcp2221 As soon as the I2C driver part will be enabled in mcp2221_probe(), the first HID reports might be exchanged with the chip due to other drivers probing for their devices on the just added I2C bus. HID I/O has to be enabled explicitly during mcp2221_probe() to receive response reports. In addition, the I2C bus' adapdata has to be set before any use of the bus, otherwise mcp_{i2c,smbus}_xfer will attempt to dereference a NULL pointer. Fixes: 67a95c21463d ("HID: mcp2221: add usb to i2c-smbus host bridge") Signed-off-by: Karl Georg Esser Signed-off-by: Sven Zühlsdorf --- drivers/hid/hid-mcp2221.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c index 5886543b17f3..35b7d6939b38 100644 --- a/drivers/hid/hid-mcp2221.c +++ b/drivers/hid/hid-mcp2221.c @@ -324,6 +324,9 @@ static int mcp_i2c_xfer(struct i2c_adapter *adapter, int ret; struct mcp2221 *mcp = i2c_get_adapdata(adapter); + if(!mcp) + return -ECONNREFUSED; + hid_hw_power(mcp->hdev, PM_HINT_FULLON); mutex_lock(&mcp->lock); @@ -433,6 +436,9 @@ static int mcp_smbus_xfer(struct i2c_adapter *adapter, u16 addr, int ret; struct mcp2221 *mcp = i2c_get_adapdata(adapter); + if(!mcp) + return -ECONNREFUSED; + hid_hw_power(mcp->hdev, PM_HINT_FULLON); mutex_lock(&mcp->lock); @@ -1148,12 +1154,14 @@ static int mcp2221_probe(struct hid_device *hdev, "MCP2221 usb-i2c bridge on hidraw%d", ((struct hidraw *)hdev->hidraw)->minor); + i2c_set_adapdata(&mcp->adapter, mcp); + hid_device_io_start(hdev); + ret = devm_i2c_add_adapter(&hdev->dev, &mcp->adapter); if (ret) { hid_err(hdev, "can't add usb-i2c adapter: %d\n", ret); return ret; } - i2c_set_adapdata(&mcp->adapter, mcp); #if IS_REACHABLE(CONFIG_GPIOLIB) /* Setup GPIO chip */