From patchwork Fri Nov 22 12:26:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 844979 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (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 B7DE41DE2DA; Fri, 22 Nov 2024 12:26:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732278407; cv=none; b=GCpWpcjC7JQ9ywRjRPzcxzzizL7UsbBLt71ViD3W7aMP9MDzmZWkXNP5AGFjfwcWk81wX3X3ioeeMZVYahPmSFWBSHyZeRWrOAiA1L5sikB1cktKWGGw+xTTonTWNedG2tfn2t2dl5wtuAKg0hqLN1V+caB1YmvrS+6ab/zP7q8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732278407; c=relaxed/simple; bh=IQNWzrAH1iBv5O3e7R2BGgKJIK7yXJflYT7NUyp5gWw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FWgSZV4HRV8RkVOWje/c3+58xNd5ymhvEcjlXblBjsQOnVRbpcFTTLbP1J+HzThtrahErcOmLS/TvQA3F5c0z641l66cQi2ifSmmL727gpodJInrgIgdyFcJtqW560c2jfOsym/qRq8Ue6iHPDn+RyLZQOc/4G+RoSonbjCGisA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=aFwrKQPG; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="aFwrKQPG" Received: from [127.0.1.1] (91-157-155-49.elisa-laajakaista.fi [91.157.155.49]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 724D7F86; Fri, 22 Nov 2024 13:26:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1732278379; bh=IQNWzrAH1iBv5O3e7R2BGgKJIK7yXJflYT7NUyp5gWw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=aFwrKQPGcFrKx1Qm7EXg2iBsQ3XewcTzrzvtteiSc0Mb/4qstKNgXe4GfHc7bjS3y r0w2g519HKDI3n2WO0W3RmIP7yH63Q/fwwVzo9Z687jjKAOISweGxGxZMKKZ4c24bC R8un0ys9JrfUw6pDNVpJedoHDQ8GTCoMAKXN4Dd8= From: Tomi Valkeinen Date: Fri, 22 Nov 2024 14:26:18 +0200 Subject: [PATCH v2 1/3] i2c: atr: Fix client detach Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241122-i2c-atr-fixes-v2-1-0acd325b6916@ideasonboard.com> References: <20241122-i2c-atr-fixes-v2-0-0acd325b6916@ideasonboard.com> In-Reply-To: <20241122-i2c-atr-fixes-v2-0-0acd325b6916@ideasonboard.com> To: Luca Ceresoli , Wolfram Sang , Andy Shevchenko , Sakari Ailus Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Wolfram Sang , Mauro Carvalho Chehab , Cosmin Tanislav , Tomi Valkeinen , Tomi Valkeinen , stable@vger.kernel.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1208; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=Jmofkmp04A8WontjwcBtEvvZ4qvWTZniF5VxGkU4/yM=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBnQHh7xqCe0gcDoAE6qj7Ocv+4zTEfYyAfARISQ DBF2DWTbFeJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZ0B4ewAKCRD6PaqMvJYe 9flkD/43MaZQnc3ShdbKozlEhQ1X6fPbuzKvkSM/Zj2vr6Iff3tE1e5J5/8ogrVGZJO3rp5JDo6 NgIM+7aFCsAD8wi7WnDxP5sb5aTab/89cXoL0dxnAX+XnWcU7XpzHbjlaeNkAfdalNAh9j1xQhU S09EroGWVU9xWbcyUdOYuhQhm6ByNhxToZ40inu0tOExIZr7A9qjhIDLQQzgCdKGXdZq1NNK6O6 teqG9MYulj3Zh0z5nvnn0cdaC+bZoBTyHGvBY7DvtT1uStvCPP7yHgpY/CPzHIdrIj5c/4n8wcq +IHZ9be/gpMsDd+5wH5v5jw4xKt0lKnTXDewjM33HpWEVlJy/b+Cdiw/2mvXILcH2Nmk5ZQykuF G+qFUvqrb0diWht0rK/r5EEcxrsQbKRTi8+Ly+CLJzCVNNnMQm9r2ktTDcm+amwe+wM3fZ7zf/Z 9cyNsIpF293zVB5laUt8j9kQdFtOKMEqnaMdu9fRSr1OfBptOK0m5uRk6zsMFLM0W1QFg7nFYfq 8/26FC9Yy4IR1mRYPs5mE5vT+KembsAWn8VacJTB5EtUI2rgQKwEt6QZCTvTQZij5iAwPsX+oOc rrB/mERtANq9EaDH0WxzDA7o1Omc4oqWGfWQ5Y04eAWMxN4a+LRvAIifPZ3HKn53ZmDZERlMFdt f5xElXnTOxj+SYA== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 From: Tomi Valkeinen i2c-atr catches the BUS_NOTIFY_DEL_DEVICE event on the bus and removes the translation by calling i2c_atr_detach_client(). However, BUS_NOTIFY_DEL_DEVICE happens when the device is about to be removed from this bus, i.e. before removal, and thus before calling .remove() on the driver. If the driver happens to do any i2c transactions in its remove(), they will fail. Fix this by catching BUS_NOTIFY_REMOVED_DEVICE instead, thus removing the translation only after the device is actually removed. Fixes: a076a860acae ("media: i2c: add I2C Address Translator (ATR) support") Cc: stable@vger.kernel.org Signed-off-by: Tomi Valkeinen Reviewed-by: Luca Ceresoli Reviewed-by: Romain Gantois Tested-by: Romain Gantois --- drivers/i2c/i2c-atr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c index f21475ae5921..0d54d0b5e327 100644 --- a/drivers/i2c/i2c-atr.c +++ b/drivers/i2c/i2c-atr.c @@ -412,7 +412,7 @@ static int i2c_atr_bus_notifier_call(struct notifier_block *nb, dev_name(dev), ret); break; - case BUS_NOTIFY_DEL_DEVICE: + case BUS_NOTIFY_REMOVED_DEVICE: i2c_atr_detach_client(client->adapter, client); break; From patchwork Fri Nov 22 12:26:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 844978 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (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 B76DE1DEFF4; Fri, 22 Nov 2024 12:26:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732278410; cv=none; b=RHTe8pYuOYcGLhDW32R+57MVOj48lO7mxIMmNQsVMJ2RzkP/JzWDLpgfwz856Qx/GGpEwAiiiTsLiWNgvftDHHAgl12pcFDv1enBYDN+2+rD56zNpRtf6frVeQ9pC0xCHOTW/qVdkP65PPwX4hnwQ+A69/F6de7Dttq6tDGeWUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732278410; c=relaxed/simple; bh=xiTFw+i+dSlZoPxbHDTsWbl3qCOr3GxjBtlNQkPNP9w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fJMBtMcNrQtVdy1QUvwbFYywFHpWgNlHZ+azgfbAU/XZcuTEbL0gdOo+zNit62l37Kww8Hx4WbjMVMyx1pRDB1YQMt1i1FaEb7KWR3I7PTfdROOVzS1u4JmvJqfNdHGsZG68hRt6W2IknctYSoyCMbUpvYmqw8ChoYqTxekQon0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=nduAWYyu; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nduAWYyu" Received: from [127.0.1.1] (91-157-155-49.elisa-laajakaista.fi [91.157.155.49]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F023C10B9; Fri, 22 Nov 2024 13:26:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1732278380; bh=xiTFw+i+dSlZoPxbHDTsWbl3qCOr3GxjBtlNQkPNP9w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=nduAWYyunmY5bC5wCazUhGER8g3Rpn2YqPRQvzc6fza+Ym0GAnhStjVHG/+KK74Bl vGscsYiVRYDRHayVahiDBfO2CKUHBPysq0KPU+cFw+blC/FQVNiLtOsUFGUbmMi8fu 8JKSS833B7FQ6386bfm69TJXnwWczudF3ZPzqNvg= From: Tomi Valkeinen Date: Fri, 22 Nov 2024 14:26:20 +0200 Subject: [PATCH v2 3/3] i2c: atr: Fix lockdep for nested ATRs Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241122-i2c-atr-fixes-v2-3-0acd325b6916@ideasonboard.com> References: <20241122-i2c-atr-fixes-v2-0-0acd325b6916@ideasonboard.com> In-Reply-To: <20241122-i2c-atr-fixes-v2-0-0acd325b6916@ideasonboard.com> To: Luca Ceresoli , Wolfram Sang , Andy Shevchenko , Sakari Ailus Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Wolfram Sang , Mauro Carvalho Chehab , Cosmin Tanislav , Tomi Valkeinen , Tomi Valkeinen X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2993; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=AgIuE1jkRE8lF7XkNaap1BLjaTjFArq2xCNquRONpxw=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBnQHh8A7VPrkIzRqsK5LqgqbHpAJ570VNLlnsrM KgeqzpRrW2JAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZ0B4fAAKCRD6PaqMvJYe 9b1tD/4/OgUxPLaZ2YsVgt0pTy2KlWhhUuX9c53dYxuBhyZnxF/jErYeyrOYPZUlPqmjfn4ZMqe POw/oudIelF/udTqGQJij3MviMeKXFPyiJR2qIkF47R/Ox/2oTyIoqKvyg9Y7WtYqblcmZAlcSz ZvuBdyHGtpi2dW0hQ9K4k1t/+Yk/ANuYZ/gbYwSS5gQigoElmS3CnLmxpv79ecy32Z2FiAM+XOH uQTlEE78gpuppJx+MEQkvRRxkfZmT2wdlfakL4zMrXs/FT2iZ+xPKzn5wMqR7aLD6+lS1uIbBv3 IjrmyUGUp4cBPBxyUT+srCdCzWmDNHbaZI+cRTH3lg1OZcv9sz8bIWnUySnmZVYqx6saAuSUvC6 zoE470ZeHLG3JP7mqeMzTUdyfNHkByhmgkHTKboxKtWI5Ebxk6U/66FzFghIqpixE83wRDtZvl7 bndJ6HDhEcsrSPqHQDOi2WGvoktFAtCpon78fjmGoz8l4PjZwt90e/iO2wJj6XNprn+gIldeyTG s5U7jRFXxwxRKCO+LLWYArpPsvbKWjubdntWtjPprtlx4KLISs8LndG+n4RzbAle3RgRAM+Dlo0 7lP7pNh1scDF9SK+PRorpFBZj87ViJBmMXjxYQKr0nQMZ4ha65htjIrBoi4OCA75mWxW2soEqJ0 SrufTl9/QEZWnpQ== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 From: Tomi Valkeinen When we have an ATR, and another ATR as a subdevice of the first ATR, we get lockdep warnings for the i2c_atr.lock and i2c_atr_chan.orig_addrs_lock. This is because lockdep uses a static key for the locks, and doesn't see the locks of the separate ATR instances as separate. Fix this by generating a dynamic lock key per lock instance. Signed-off-by: Tomi Valkeinen --- drivers/i2c/i2c-atr.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c index 5adb720af84e..5cc18606bca9 100644 --- a/drivers/i2c/i2c-atr.c +++ b/drivers/i2c/i2c-atr.c @@ -54,6 +54,7 @@ struct i2c_atr_chan { /* Lock orig_addrs during xfer */ struct mutex orig_addrs_lock; + struct lock_class_key orig_addrs_lock_key; u16 *orig_addrs; unsigned int orig_addrs_size; }; @@ -84,6 +85,7 @@ struct i2c_atr { struct i2c_algorithm algo; /* lock for the I2C bus segment (see struct i2c_lock_operations) */ struct mutex lock; + struct lock_class_key lock_key; int max_adapters; size_t num_aliases; @@ -505,7 +507,9 @@ struct i2c_atr *i2c_atr_new(struct i2c_adapter *parent, struct device *dev, if (!atr) return ERR_PTR(-ENOMEM); - mutex_init(&atr->lock); + lockdep_register_key(&atr->lock_key); + mutex_init_with_key(&atr->lock, &atr->lock_key); + spin_lock_init(&atr->alias_mask_lock); atr->parent = parent; @@ -535,6 +539,7 @@ struct i2c_atr *i2c_atr_new(struct i2c_adapter *parent, struct device *dev, kfree(atr->aliases); err_destroy_mutex: mutex_destroy(&atr->lock); + lockdep_unregister_key(&atr->lock_key); kfree(atr); return ERR_PTR(ret); @@ -552,6 +557,7 @@ void i2c_atr_delete(struct i2c_atr *atr) bitmap_free(atr->alias_use_mask); kfree(atr->aliases); mutex_destroy(&atr->lock); + lockdep_unregister_key(&atr->lock_key); kfree(atr); } EXPORT_SYMBOL_NS_GPL(i2c_atr_delete, I2C_ATR); @@ -586,7 +592,8 @@ int i2c_atr_add_adapter(struct i2c_atr *atr, u32 chan_id, chan->atr = atr; chan->chan_id = chan_id; INIT_LIST_HEAD(&chan->alias_list); - mutex_init(&chan->orig_addrs_lock); + lockdep_register_key(&chan->orig_addrs_lock_key); + mutex_init_with_key(&chan->orig_addrs_lock, &chan->orig_addrs_lock_key); snprintf(chan->adap.name, sizeof(chan->adap.name), "i2c-%d-atr-%d", i2c_adapter_id(parent), chan_id); @@ -646,6 +653,7 @@ int i2c_atr_add_adapter(struct i2c_atr *atr, u32 chan_id, err_fwnode_put: fwnode_handle_put(dev_fwnode(&chan->adap.dev)); mutex_destroy(&chan->orig_addrs_lock); + lockdep_unregister_key(&chan->orig_addrs_lock_key); kfree(chan); return ret; } @@ -679,6 +687,7 @@ void i2c_atr_del_adapter(struct i2c_atr *atr, u32 chan_id) fwnode_handle_put(fwnode); mutex_destroy(&chan->orig_addrs_lock); + lockdep_unregister_key(&chan->orig_addrs_lock_key); kfree(chan->orig_addrs); kfree(chan); }