Message ID | 20221229160045.535778-2-brgl@bgdev.pl |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2476339wrt; Thu, 29 Dec 2022 08:11:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXuUXtfups73Cog5+h3aO2vRNrJz7BiCxsncMlSgc8zbTPsdYoRIiHUqBUD4+e/6cF56Vx4C X-Received: by 2002:a17:907:9d0b:b0:78d:f455:30db with SMTP id kt11-20020a1709079d0b00b0078df45530dbmr25442419ejc.3.1672330296996; Thu, 29 Dec 2022 08:11:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672330296; cv=none; d=google.com; s=arc-20160816; b=L7wuq4goHFTVfcvjEv+PvILoqAUmYkQReyAxlyrgkGfaVxMuJPQZhfevewEb9RX6St M4yloYXIfoTyn9ydNxw6GRXSdw+9AIu65PfYQRyw9Lk3e3hpbvvZsyRcJgoXEU67r57l 9L530n97IzMXsuBagfu9z44kvdZks/wh9FcsaNuRq1kIwmr/c/5envdij9NmpAYokDCR C2bfR21DvGv98/4gi5SjARnuGUoy8y4RqtJXhy2adBFeDe98K3lY5EtYDIMFvH7lJmKb g6t98fuwrLa0CTbOlClxZyOk+4mcxTV1obCGaHNY/IdwjHVz9yE7fq/og80DYcyEguyz SKbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rU7sDwiy4wxWca9BJshy+agHeUQnApN7sCu5RKlRtdM=; b=x894NjaMfN7Rs1rDyLTeMlYclShIdHHaHA3/JeREuEweAzZ0ARTyPkcLkTk3KAWDkE VlFp5NjuoJqcdNx+H59EcnQwr8jy6XxgGiPm5uZQFrSjJi059ZkjYafZlZ/+Li7Lgc+n cndPJH1xmQAHN/jtC/G5U2w8/yxmWocngAyKnbt5kWpdGuDV05baOW28xZXm3RCYk5mQ Tghd6uVsJZOOlODAD9neAWFgxxXV+VDOdHmj5JZXvNqJYaorAlaXiJWKVR1OnBOScSui DiCx6C8CrVNFYHCwBeqE5UlzALWFDka4S5xJ0FBAq49YYgiMbh+Bf6mtj6L1/DyX1JIr GA+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20210112.gappssmtp.com header.s=20210112 header.b="QMG0v/1n"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb25-20020a1709077e9900b0084bbd97edc4si13895218ejc.573.2022.12.29.08.11.12; Thu, 29 Dec 2022 08:11:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20210112.gappssmtp.com header.s=20210112 header.b="QMG0v/1n"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233645AbiL2QA4 (ORCPT <rfc822;eddaouddi.ayoub@gmail.com> + 99 others); Thu, 29 Dec 2022 11:00:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233548AbiL2QAw (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 29 Dec 2022 11:00:52 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27D46C2A for <linux-kernel@vger.kernel.org>; Thu, 29 Dec 2022 08:00:51 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id k26-20020a05600c1c9a00b003d972646a7dso10342462wms.5 for <linux-kernel@vger.kernel.org>; Thu, 29 Dec 2022 08:00:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20210112.gappssmtp.com; s=20210112; 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=rU7sDwiy4wxWca9BJshy+agHeUQnApN7sCu5RKlRtdM=; b=QMG0v/1nbi8hZ9k+X70DoEIE//b9nhmqplfikAPHlsmTZe0xNR2l8nbm2O0DqduQEp d5uEnccRjQpPn3ruyZ1t7DEuKhwxuQGVmpJoUtDbHF61PKSy+MNX7c3QaSS+LmKGA9h4 Cj7SCwh1kzAWFjTGnCER9W7spZKATQR/wfjGZu4qOTBL9sb4RSfPgcSfaqJlUmO2m/B1 nXpNroyIn3zjqGtPwPHUuHorNkwTKe5uP1L+hCqPFNrDZcYkJY/XrIWqmJL25pad4GC/ rW2CJyVUI4dw/irPK1J2hAwnjnc7rDGMxWBHAQ045TexoC72zdqEADUK9FdApcoCtbGO d5Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=rU7sDwiy4wxWca9BJshy+agHeUQnApN7sCu5RKlRtdM=; b=qaAL/1MqcFNQm2Z89IsWi+Ob7YELrZxp8nCSKzinQ6r29LKiHxmDY9lDl6CblIfApY D3nWjAd1wxcHPmJaz/a0d/jhyhJ2ychl54cYu+cDa3sZRJiQV2tHq3e2+2ZGf2fb5eHU FhwpZGMXX5dPrxdwP84cLmRz9B2b8D3w6zafdbeKy4TGhUYTXHghbvjPri7uhJKBTGVL 3qrloaJPXza0Ef6aCJ8oxuPVW4hOchHCunTCxdABX1HSVL65joJNSOtm+Htp2T0ab2p1 pHRwKwDyRiIJTz1yXZhr1eNggEy5cLEmR7tshRXHzKytNZJV+Y7Ev75Jv/YNcDokzqP4 T1og== X-Gm-Message-State: AFqh2kobRPaZjtZqg4zC8ft9NWqPWJXgGuphuae1103f8gtSzh4VvMuu IumObFUmGyMQUYo+e5zaNnkD27RSM7s99SuX X-Received: by 2002:a05:600c:4995:b0:3d3:4f43:fbc2 with SMTP id h21-20020a05600c499500b003d34f43fbc2mr20646046wmp.41.1672329649761; Thu, 29 Dec 2022 08:00:49 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:8f7a:98d8:9d8d:ced8]) by smtp.gmail.com with ESMTPSA id c12-20020a05600c0a4c00b003cfa3a12660sm42511593wmq.1.2022.12.29.08.00.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 08:00:49 -0800 (PST) From: Bartosz Golaszewski <brgl@bgdev.pl> To: Wolfram Sang <wsa@kernel.org> Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Subject: [PATCH v2 1/2] i2c: dev: fix notifier return values Date: Thu, 29 Dec 2022 17:00:44 +0100 Message-Id: <20221229160045.535778-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221229160045.535778-1-brgl@bgdev.pl> References: <20221229160045.535778-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753565413389299873?= X-GMAIL-MSGID: =?utf-8?q?1753565413389299873?= |
Series |
i2c: fortify the subsystem against user-space induced deadlocks
|
|
Commit Message
Bartosz Golaszewski
Dec. 29, 2022, 4 p.m. UTC
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> We have a set of return values that notifier callbacks can return. They should not return 0, error codes or anything other than those predefined values. Make the i2c character device's callback return NOTIFY_DONE or NOTIFY_OK depending on the situation. Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> --- drivers/i2c/i2c-dev.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
Comments
On Thu, Dec 29, 2022 at 05:00:44PM +0100, Bartosz Golaszewski wrote: > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > We have a set of return values that notifier callbacks can return. They > should not return 0, error codes or anything other than those predefined > values. Make the i2c character device's callback return NOTIFY_DONE or > NOTIFY_OK depending on the situation. > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Applied to for-next, thanks! I start reviewing patch 2 now...
Hi Bartosz, On Thu, Dec 29, 2022 at 5:12 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > We have a set of return values that notifier callbacks can return. They > should not return 0, error codes or anything other than those predefined > values. Make the i2c character device's callback return NOTIFY_DONE or > NOTIFY_OK depending on the situation. > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Thanks for your patch, which is now commit cddf70d0bce71c2a ("i2c: dev: fix notifier return values") in v6.3-rc1. On SH/R-Mobile platforms, this leads to missing /dev/i2c-* entries. On R-Car Gen4, they are still present, as all I2C adapters are initialized after i2cdev. > --- a/drivers/i2c/i2c-dev.c > +++ b/drivers/i2c/i2c-dev.c > @@ -653,12 +653,12 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy) > int res; > > if (dev->type != &i2c_adapter_type) > - return 0; > + return NOTIFY_DONE; > adap = to_i2c_adapter(dev); > > i2c_dev = get_free_i2c_dev(adap); > if (IS_ERR(i2c_dev)) > - return PTR_ERR(i2c_dev); > + return NOTIFY_DONE; > > cdev_init(&i2c_dev->cdev, &i2cdev_fops); > i2c_dev->cdev.owner = THIS_MODULE; > @@ -678,11 +678,11 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy) > goto err_put_i2c_dev; > > pr_debug("adapter [%s] registered as minor %d\n", adap->name, adap->nr); > - return 0; > + return NOTIFY_OK; Unfortunately i2cdev_{at,de}tach_adapter() are not only used as notifiers (called from i2cdev_notifier_call()), but also called from i2c_dev_init(): /* Bind to already existing adapters right away */ i2c_for_each_dev(NULL, i2cdev_attach_adapter); and i2c_dev_exit(): i2c_for_each_dev(NULL, i2cdev_detach_adapter); As soon i2c_dev_{at,de}tach_adapter() returns a non-zero value (e.g. NOTIFY_OK), {i2c,bus}_for_each_dev() aborts processing. In i2c_dev_init(), this leads to a failure in registering any already existing i2c adapters after the first one, causing missing /dev/i2c-* entries. In i2c_dev_exit(), this leads to a failure unregistering any but the first i2c adapter. As there is no one-to-one mapping from error codes to notify codes, I think this cannot just be handled inside i2cdev_notifier_call() :-( Gr{oetje,eeting}s, Geert
On Wed, Mar 8, 2023 at 5:58 PM Geert Uytterhoeven <geert@linux-m68k.org> wrote: > > Hi Bartosz, > > On Thu, Dec 29, 2022 at 5:12 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > > > We have a set of return values that notifier callbacks can return. They > > should not return 0, error codes or anything other than those predefined > > values. Make the i2c character device's callback return NOTIFY_DONE or > > NOTIFY_OK depending on the situation. > > > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > Thanks for your patch, which is now commit cddf70d0bce71c2a ("i2c: > dev: fix notifier return values") in v6.3-rc1. > > On SH/R-Mobile platforms, this leads to missing /dev/i2c-* entries. > On R-Car Gen4, they are still present, as all I2C adapters are > initialized after i2cdev. > > > --- a/drivers/i2c/i2c-dev.c > > +++ b/drivers/i2c/i2c-dev.c > > @@ -653,12 +653,12 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy) > > int res; > > > > if (dev->type != &i2c_adapter_type) > > - return 0; > > + return NOTIFY_DONE; > > adap = to_i2c_adapter(dev); > > > > i2c_dev = get_free_i2c_dev(adap); > > if (IS_ERR(i2c_dev)) > > - return PTR_ERR(i2c_dev); > > + return NOTIFY_DONE; > > > > cdev_init(&i2c_dev->cdev, &i2cdev_fops); > > i2c_dev->cdev.owner = THIS_MODULE; > > @@ -678,11 +678,11 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy) > > goto err_put_i2c_dev; > > > > pr_debug("adapter [%s] registered as minor %d\n", adap->name, adap->nr); > > - return 0; > > + return NOTIFY_OK; > > Unfortunately i2cdev_{at,de}tach_adapter() are not only used as > notifiers (called from i2cdev_notifier_call()), but also called from > i2c_dev_init(): > > /* Bind to already existing adapters right away */ > i2c_for_each_dev(NULL, i2cdev_attach_adapter); > > and i2c_dev_exit(): > > i2c_for_each_dev(NULL, i2cdev_detach_adapter); > > As soon i2c_dev_{at,de}tach_adapter() returns a non-zero > value (e.g. NOTIFY_OK), {i2c,bus}_for_each_dev() aborts > processing. > > In i2c_dev_init(), this leads to a failure in registering any > already existing i2c adapters after the first one, causing missing > /dev/i2c-* entries. > > In i2c_dev_exit(), this leads to a failure unregistering any but the > first i2c adapter. > > As there is no one-to-one mapping from error codes to notify codes, > I think this cannot just be handled inside i2cdev_notifier_call() :-( > Would wrapping i2c_a/detach_adapter() in a notifier callback work? So that SH can call it directly while notifiers would call it indirectly through the wrapper? Bart
Hi Bartosz, On Wed, Mar 8, 2023 at 8:33 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > On Wed, Mar 8, 2023 at 5:58 PM Geert Uytterhoeven <geert@linux-m68k.org> wrote: > > On Thu, Dec 29, 2022 at 5:12 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > > > > > We have a set of return values that notifier callbacks can return. They > > > should not return 0, error codes or anything other than those predefined > > > values. Make the i2c character device's callback return NOTIFY_DONE or > > > NOTIFY_OK depending on the situation. > > > > > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > > > Thanks for your patch, which is now commit cddf70d0bce71c2a ("i2c: > > dev: fix notifier return values") in v6.3-rc1. > > > > On SH/R-Mobile platforms, this leads to missing /dev/i2c-* entries. > > On R-Car Gen4, they are still present, as all I2C adapters are > > initialized after i2cdev. > > > > > --- a/drivers/i2c/i2c-dev.c > > > +++ b/drivers/i2c/i2c-dev.c > > > @@ -653,12 +653,12 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy) > > > int res; > > > > > > if (dev->type != &i2c_adapter_type) > > > - return 0; > > > + return NOTIFY_DONE; > > > adap = to_i2c_adapter(dev); > > > > > > i2c_dev = get_free_i2c_dev(adap); > > > if (IS_ERR(i2c_dev)) > > > - return PTR_ERR(i2c_dev); > > > + return NOTIFY_DONE; > > > > > > cdev_init(&i2c_dev->cdev, &i2cdev_fops); > > > i2c_dev->cdev.owner = THIS_MODULE; > > > @@ -678,11 +678,11 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy) > > > goto err_put_i2c_dev; > > > > > > pr_debug("adapter [%s] registered as minor %d\n", adap->name, adap->nr); > > > - return 0; > > > + return NOTIFY_OK; > > > > Unfortunately i2cdev_{at,de}tach_adapter() are not only used as > > notifiers (called from i2cdev_notifier_call()), but also called from > > i2c_dev_init(): > > > > /* Bind to already existing adapters right away */ > > i2c_for_each_dev(NULL, i2cdev_attach_adapter); > > > > and i2c_dev_exit(): > > > > i2c_for_each_dev(NULL, i2cdev_detach_adapter); > > > > As soon i2c_dev_{at,de}tach_adapter() returns a non-zero > > value (e.g. NOTIFY_OK), {i2c,bus}_for_each_dev() aborts > > processing. > > > > In i2c_dev_init(), this leads to a failure in registering any > > already existing i2c adapters after the first one, causing missing > > /dev/i2c-* entries. > > > > In i2c_dev_exit(), this leads to a failure unregistering any but the > > first i2c adapter. > > > > As there is no one-to-one mapping from error codes to notify codes, > > I think this cannot just be handled inside i2cdev_notifier_call() :-( > > Would wrapping i2c_a/detach_adapter() in a notifier callback work? So > that SH can call it directly while notifiers would call it indirectly > through the wrapper? That would be a wrapper that ignores the NOTIFY_* return value, and always returns zero? I.e. we can no longer return an error. I guess that's OK, as i2c_dev_init() doesn't take any action based on the returned error code anyway. The only error conditions that can happen in i2c_attach_adapter() are: - "Out of device minors" message in get_free_i2c_dev(), - WARN_ON(dev == WHITEOUT_DEV) in cdev_add(), - Generic -ENOMEM. Looks like all of the above can be ignored, as they are all unlikely to happen, and there is nothing to be done to recover... Note that this is not "called directly from SH". The SH/R-Mobile SoCs where I noticed the issue are ARM32. I guess it can happen on other platforms, too, depending on initialization order... Gr{oetje,eeting}s, Geert
Hi Bartosz, On Wed, Mar 8, 2023 at 8:51 PM Geert Uytterhoeven <geert@linux-m68k.org> wrote: > On Wed, Mar 8, 2023 at 8:33 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > > On Wed, Mar 8, 2023 at 5:58 PM Geert Uytterhoeven <geert@linux-m68k.org> wrote: > > > On Thu, Dec 29, 2022 at 5:12 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > > > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > > > > > > > We have a set of return values that notifier callbacks can return. They > > > > should not return 0, error codes or anything other than those predefined > > > > values. Make the i2c character device's callback return NOTIFY_DONE or > > > > NOTIFY_OK depending on the situation. > > > > > > > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > > > > > Thanks for your patch, which is now commit cddf70d0bce71c2a ("i2c: > > > dev: fix notifier return values") in v6.3-rc1. > > > > > > On SH/R-Mobile platforms, this leads to missing /dev/i2c-* entries. > > > On R-Car Gen4, they are still present, as all I2C adapters are > > > initialized after i2cdev. > > > > > > > --- a/drivers/i2c/i2c-dev.c > > > > +++ b/drivers/i2c/i2c-dev.c > > > > @@ -653,12 +653,12 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy) > > > > int res; > > > > > > > > if (dev->type != &i2c_adapter_type) > > > > - return 0; > > > > + return NOTIFY_DONE; > > > > adap = to_i2c_adapter(dev); > > > > > > > > i2c_dev = get_free_i2c_dev(adap); > > > > if (IS_ERR(i2c_dev)) > > > > - return PTR_ERR(i2c_dev); > > > > + return NOTIFY_DONE; > > > > > > > > cdev_init(&i2c_dev->cdev, &i2cdev_fops); > > > > i2c_dev->cdev.owner = THIS_MODULE; > > > > @@ -678,11 +678,11 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy) > > > > goto err_put_i2c_dev; > > > > > > > > pr_debug("adapter [%s] registered as minor %d\n", adap->name, adap->nr); > > > > - return 0; > > > > + return NOTIFY_OK; > > > > > > Unfortunately i2cdev_{at,de}tach_adapter() are not only used as > > > notifiers (called from i2cdev_notifier_call()), but also called from > > > i2c_dev_init(): > > > > > > /* Bind to already existing adapters right away */ > > > i2c_for_each_dev(NULL, i2cdev_attach_adapter); > > > > > > and i2c_dev_exit(): > > > > > > i2c_for_each_dev(NULL, i2cdev_detach_adapter); > > > > > > As soon i2c_dev_{at,de}tach_adapter() returns a non-zero > > > value (e.g. NOTIFY_OK), {i2c,bus}_for_each_dev() aborts > > > processing. > > > > > > In i2c_dev_init(), this leads to a failure in registering any > > > already existing i2c adapters after the first one, causing missing > > > /dev/i2c-* entries. > > > > > > In i2c_dev_exit(), this leads to a failure unregistering any but the > > > first i2c adapter. > > > > > > As there is no one-to-one mapping from error codes to notify codes, > > > I think this cannot just be handled inside i2cdev_notifier_call() :-( > > > > Would wrapping i2c_a/detach_adapter() in a notifier callback work? So > > that SH can call it directly while notifiers would call it indirectly > > through the wrapper? > > That would be a wrapper that ignores the NOTIFY_* return > value, and always returns zero? I.e. we can no longer return an > error. I guess that's OK, as i2c_dev_init() doesn't take any > action based on the returned error code anyway. This works, so I've sent a fix https://lore.kernel.org/r/03a8cd13af352c4d990bc70b72df4915b9fa2874.1678347776.git.geert+renesas@glider.be Gr{oetje,eeting}s, Geert
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index ab0adaa130da..107623c4cc14 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c @@ -653,12 +653,12 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy) int res; if (dev->type != &i2c_adapter_type) - return 0; + return NOTIFY_DONE; adap = to_i2c_adapter(dev); i2c_dev = get_free_i2c_dev(adap); if (IS_ERR(i2c_dev)) - return PTR_ERR(i2c_dev); + return NOTIFY_DONE; cdev_init(&i2c_dev->cdev, &i2cdev_fops); i2c_dev->cdev.owner = THIS_MODULE; @@ -678,11 +678,11 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy) goto err_put_i2c_dev; pr_debug("adapter [%s] registered as minor %d\n", adap->name, adap->nr); - return 0; + return NOTIFY_OK; err_put_i2c_dev: put_i2c_dev(i2c_dev, false); - return res; + return NOTIFY_DONE; } static int i2cdev_detach_adapter(struct device *dev, void *dummy) @@ -691,17 +691,17 @@ static int i2cdev_detach_adapter(struct device *dev, void *dummy) struct i2c_dev *i2c_dev; if (dev->type != &i2c_adapter_type) - return 0; + return NOTIFY_DONE; adap = to_i2c_adapter(dev); i2c_dev = i2c_dev_get_by_minor(adap->nr); if (!i2c_dev) /* attach_adapter must have failed */ - return 0; + return NOTIFY_DONE; put_i2c_dev(i2c_dev, true); pr_debug("adapter [%s] unregistered\n", adap->name); - return 0; + return NOTIFY_OK; } static int i2cdev_notifier_call(struct notifier_block *nb, unsigned long action, @@ -716,7 +716,7 @@ static int i2cdev_notifier_call(struct notifier_block *nb, unsigned long action, return i2cdev_detach_adapter(dev, NULL); } - return 0; + return NOTIFY_DONE; } static struct notifier_block i2cdev_notifier = {