Message ID | 20240216125959.3766309-1-arnd@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-68603-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp494068dyb; Fri, 16 Feb 2024 05:03:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWXU/ZCKd5uIYcDdNi6VT4axZI11JOIdt7XIxkgzHcfIF3/TpoAbWawUJWqgp+ceP2YorlFPQF4zHFn5P/dYdUS1vhumg== X-Google-Smtp-Source: AGHT+IFdWoC9xmFw9MG1fD08PIRTi+P3vezpfU4rDO6wP/OHoW2k2m0vEmXRK2DoI8eWgeKRGmnp X-Received: by 2002:a17:902:f68a:b0:1db:4287:c309 with SMTP id l10-20020a170902f68a00b001db4287c309mr4639314plg.11.1708088590753; Fri, 16 Feb 2024 05:03:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708088590; cv=pass; d=google.com; s=arc-20160816; b=RkG9Fa8BVmV1yGa+RuchAJ0K23A3uEJqisv6wdtjnsnFbuT4GxQEq3U+pEcPNc7c1P OA5JpaDxxihUVF+RQE2LSoUcyoA8r8vhs+TILnsQ7szxDdcm+H/F8yPvoT06F6Ip5EXy GCahzrFGGwzedzXJNyZufKDQU0nL2ElHh4UZ6x7FZPjYIISvd/ASG1xDlRz2EivGFUgf fmEco7vUiH6gAPY+qzTTkNaD8qdd8c/fkYro4tPHf/p2gho28KPwskdZcQcuOx+93HdU NC0KU0rur02IrcIaYhhrLRAfmtkoYrLwjtRhnov0c71YhZQnsDEbXjdWoflJpGW3GsUJ cLfA== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=zGXKsXy51gCJICrOkl6rSU4KrFKit0QjMm02SUIQI4M=; fh=dRQP0hx5XHjIU2/wzQWJ/Mhz5BphUU9mbrcUM82OYFk=; b=YPpmeO4C0qNU4kjuHtJ8tdmxgcbPcCMDEBjMalty/LPfgBhmUYw1QpRMO04GIwp+3m PKI5HqHL1gNhkSoZ3VSAMfqCe/yd2thPsNthZwXeIcDb6OPND8atGARLyI7Qx2hYhOVk 7nqiMPe192Twd6JZGI/T4PcRZv+hg04TPbJ9UEwAIx6j5tPLI5WfeRt279lRoTjOoLvV 1eQI6Uunl71SB73ImimXaRfSEV71r55syJDePMwP3Fnu9AXHW8dTVqDJYT2/ovwwbOSZ byRl1hJDM+9O2MwXIhHYzHK8DqPgeQEZaB494Bs76S35O8lGkLz8CiQIX4TayWRPRXW2 /U5A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gMybALGW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-68603-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68603-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id a26-20020a637f1a000000b005dc785e4a28si2929467pgd.30.2024.02.16.05.03.10 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 05:03:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68603-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gMybALGW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-68603-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68603-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id D4052B2346C for <ouuuleilei@gmail.com>; Fri, 16 Feb 2024 13:00:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A71B2129A69; Fri, 16 Feb 2024 13:00:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gMybALGW" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 23A5B128825; Fri, 16 Feb 2024 13:00:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708088406; cv=none; b=nti9srGrutdir8DnS78cH+Fm3aYTAe/RxJx0E2iLDh/n4Q9zt3IMBuvUqalm0EslaqI0HVgTK4pSdv1qoHwZXkR2uGSPFzx4YRW9hEug5XufP/Dj9IAQos7sk5t7s2UZnLqFliUv+Tp7/57rE4hQeela1dunOcBg7K+GCIwFhRg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708088406; c=relaxed/simple; bh=Fua+75fYl25KxH7zo3jRCWk4YuWrcZJH5ZiE41IuRQo=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=H5otpB7D1QWo65S0DPyofP0h9cnn3Vs45gHHP/ACHG5e3NvjZQ+hUs9zMtyggWIY+o6GjNaOGZlBIfQGLM1yYqx/MnHRcmkrkMtOUifFI++1xBQJV4GtRXbnWtvX8E176CeEUmUou4sMvQG+QcRsqTVgf3bqJ7ZKv9FMx650Af8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gMybALGW; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA108C433F1; Fri, 16 Feb 2024 13:00:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708088405; bh=Fua+75fYl25KxH7zo3jRCWk4YuWrcZJH5ZiE41IuRQo=; h=From:To:Cc:Subject:Date:From; b=gMybALGWtGK83QV3RuisQujmIX6Z4uGLabFhmq/aPfU55noI54gh4xVKrs7LKpqYd aOexQACIOuVuHmktqpnUMhdZ/qO1Gzk9Fxm//zDVee/4CWAl/X1NSy4/HF0FGLFETi dxe3r+SKrQt0jGDtAmf3ItVUr2S8/g5s4Avv1U4MUZnKM6oUeHtqY/PRYH6FfCiLhD PLp++c+NQSzMVXU4aKlfJegtGhXGnrJOBF0SFvNW5HkP3eMzGiBqg7FjF+jfOc0Cer QbgNgThIZ/XwpmiG0P+bq+aMyybYRI9dKWz5m7H7BbQSHsRM9QYPReMjOyeha1n/f6 JXzbMGIybuwjg== From: Arnd Bergmann <arnd@kernel.org> To: Bartosz Golaszewski <brgl@bgdev.pl>, Linus Walleij <linus.walleij@linaro.org>, "Paul E. McKenney" <paulmck@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de>, Kent Gibson <warthog618@gmail.com>, Andy Shevchenko <andriy.shevchenko@linux.intel.com>, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] gpio: cdev: avoid uninitialized variable dereference Date: Fri, 16 Feb 2024 13:59:50 +0100 Message-Id: <20240216125959.3766309-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791060701918868785 X-GMAIL-MSGID: 1791060701918868785 |
Series |
gpio: cdev: avoid uninitialized variable dereference
|
|
Commit Message
Arnd Bergmann
Feb. 16, 2024, 12:59 p.m. UTC
From: Arnd Bergmann <arnd@arndb.de> The 'gc' variable is never set before it gets printed: drivers/gpio/gpiolib-cdev.c:2802:11: error: variable 'gc' is uninitialized when used here [-Werror,-Wuninitialized] 2802 | chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id); | ^~ drivers/gpio/gpiolib.h:277:11: note: expanded from macro 'chip_dbg' 277 | dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) | ^~ Use dev_dbg() directly. Fixes: 8574b5b47610 ("gpio: cdev: use correct pointer accessors with SRCU") Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- drivers/gpio/gpiolib-cdev.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Comments
On Fri, Feb 16, 2024 at 2:00 PM Arnd Bergmann <arnd@kernel.org> wrote: > > From: Arnd Bergmann <arnd@arndb.de> > > The 'gc' variable is never set before it gets printed: > > drivers/gpio/gpiolib-cdev.c:2802:11: error: variable 'gc' is uninitialized when used here [-Werror,-Wuninitialized] > 2802 | chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id); > | ^~ > drivers/gpio/gpiolib.h:277:11: note: expanded from macro 'chip_dbg' > 277 | dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) > | ^~ > > Use dev_dbg() directly. > > Fixes: 8574b5b47610 ("gpio: cdev: use correct pointer accessors with SRCU") > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- Hi Arnd, I seem to have beat you to it[1] and my patch doesn't change the log message so I'll apply it instead of this one. Thanks, Bartosz [1] https://lore.kernel.org/linux-gpio/1542ef65-508b-45be-ad5c-63ad124cb1a2@samsung.com/T/#t
On Fri, Feb 16, 2024, at 14:19, Bartosz Golaszewski wrote: > On Fri, Feb 16, 2024 at 2:00 PM Arnd Bergmann <arnd@kernel.org> wrote: >> >> From: Arnd Bergmann <arnd@arndb.de> >> >> The 'gc' variable is never set before it gets printed: >> >> drivers/gpio/gpiolib-cdev.c:2802:11: error: variable 'gc' is uninitialized when used here [-Werror,-Wuninitialized] >> 2802 | chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id); >> | ^~ >> drivers/gpio/gpiolib.h:277:11: note: expanded from macro 'chip_dbg' >> 277 | dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) >> | ^~ >> >> Use dev_dbg() directly. >> >> Fixes: 8574b5b47610 ("gpio: cdev: use correct pointer accessors with SRCU") >> Signed-off-by: Arnd Bergmann <arnd@arndb.de> >> --- > > I seem to have beat you to it[1] and my patch doesn't change the log > message so I'll apply it instead of this one. Ok, thanks. I thought about doing this, but could not figure out which of the RCU primitives to use. Arnd
On Fri, Feb 16, 2024 at 03:04:14PM +0100, Arnd Bergmann wrote: > On Fri, Feb 16, 2024, at 14:19, Bartosz Golaszewski wrote: > > On Fri, Feb 16, 2024 at 2:00 PM Arnd Bergmann <arnd@kernel.org> wrote: > >> > >> From: Arnd Bergmann <arnd@arndb.de> > >> > >> The 'gc' variable is never set before it gets printed: > >> > >> drivers/gpio/gpiolib-cdev.c:2802:11: error: variable 'gc' is uninitialized when used here [-Werror,-Wuninitialized] > >> 2802 | chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id); > >> | ^~ > >> drivers/gpio/gpiolib.h:277:11: note: expanded from macro 'chip_dbg' > >> 277 | dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) > >> | ^~ > >> > >> Use dev_dbg() directly. > >> > >> Fixes: 8574b5b47610 ("gpio: cdev: use correct pointer accessors with SRCU") > >> Signed-off-by: Arnd Bergmann <arnd@arndb.de> > >> --- > > > > I seem to have beat you to it[1] and my patch doesn't change the log > > message so I'll apply it instead of this one. > > Ok, thanks. I thought about doing this, but could not > figure out which of the RCU primitives to use. I will count that as a bug against RCU's documentation, but I am not sure how to fix it. Thoughts? Thanx, Paul
On Fri, Feb 16, 2024, at 16:51, Paul E. McKenney wrote: > On Fri, Feb 16, 2024 at 03:04:14PM +0100, Arnd Bergmann wrote: >> On Fri, Feb 16, 2024, at 14:19, Bartosz Golaszewski wrote: >> > On Fri, Feb 16, 2024 at 2:00 PM Arnd Bergmann <arnd@kernel.org> wrote: >> >> >> >> From: Arnd Bergmann <arnd@arndb.de> >> >> >> >> The 'gc' variable is never set before it gets printed: >> >> >> >> drivers/gpio/gpiolib-cdev.c:2802:11: error: variable 'gc' is uninitialized when used here [-Werror,-Wuninitialized] >> >> 2802 | chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id); >> >> | ^~ >> >> drivers/gpio/gpiolib.h:277:11: note: expanded from macro 'chip_dbg' >> >> 277 | dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) >> >> | ^~ >> >> >> >> Use dev_dbg() directly. >> >> >> >> Fixes: 8574b5b47610 ("gpio: cdev: use correct pointer accessors with SRCU") >> >> Signed-off-by: Arnd Bergmann <arnd@arndb.de> >> >> --- >> > >> > I seem to have beat you to it[1] and my patch doesn't change the log >> > message so I'll apply it instead of this one. >> >> Ok, thanks. I thought about doing this, but could not >> figure out which of the RCU primitives to use. > > I will count that as a bug against RCU's documentation, but I am not > sure how to fix it. Thoughts? I didn't really try at all, I just figured I could avoid thinking about it by using the device pointer at hand. I'm sure the docs would have told me if I had bothered to look. Arnd
On Fri, Feb 16, 2024 at 05:17:06PM +0100, Arnd Bergmann wrote: > On Fri, Feb 16, 2024, at 16:51, Paul E. McKenney wrote: > > On Fri, Feb 16, 2024 at 03:04:14PM +0100, Arnd Bergmann wrote: > >> On Fri, Feb 16, 2024, at 14:19, Bartosz Golaszewski wrote: > >> > On Fri, Feb 16, 2024 at 2:00 PM Arnd Bergmann <arnd@kernel.org> wrote: > >> >> > >> >> From: Arnd Bergmann <arnd@arndb.de> > >> >> > >> >> The 'gc' variable is never set before it gets printed: > >> >> > >> >> drivers/gpio/gpiolib-cdev.c:2802:11: error: variable 'gc' is uninitialized when used here [-Werror,-Wuninitialized] > >> >> 2802 | chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id); > >> >> | ^~ > >> >> drivers/gpio/gpiolib.h:277:11: note: expanded from macro 'chip_dbg' > >> >> 277 | dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) > >> >> | ^~ > >> >> > >> >> Use dev_dbg() directly. > >> >> > >> >> Fixes: 8574b5b47610 ("gpio: cdev: use correct pointer accessors with SRCU") > >> >> Signed-off-by: Arnd Bergmann <arnd@arndb.de> > >> >> --- > >> > > >> > I seem to have beat you to it[1] and my patch doesn't change the log > >> > message so I'll apply it instead of this one. > >> > >> Ok, thanks. I thought about doing this, but could not > >> figure out which of the RCU primitives to use. > > > > I will count that as a bug against RCU's documentation, but I am not > > sure how to fix it. Thoughts? > > I didn't really try at all, I just figured I could avoid > thinking about it by using the device pointer at hand. > > I'm sure the docs would have told me if I had bothered to look. OK, a low-priority bug against RCU's documentation, then. ;-) Thanx, paul
diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 85037fa4925e..d6e8d2b7ac8f 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -2783,7 +2783,6 @@ static const struct file_operations gpio_fileops = { int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt) { - struct gpio_chip *gc; int ret; cdev_init(&gdev->chrdev, &gpio_fileops); @@ -2799,7 +2798,7 @@ int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt) if (!rcu_access_pointer(gdev->chip)) return -ENODEV; - chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id); + dev_dbg(&gdev->dev, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id); return 0; }