mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: oe-kbuild@lists.linux.dev,
	Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Cc: lkp@intel.com, oe-kbuild-all@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	Linus Walleij <linus.walleij@linaro.org>
Subject: drivers/gpio/gpiolib.c:4732 gpiod_find_and_request() warn: 'desc' can also be NULL
Date: Sat, 11 Apr 2026 11:00:27 +0300	[thread overview]
Message-ID: <202604110938.6uIVnQtT-lkp@intel.com> (raw)

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   7c6c4ed80b874f721bc7c2c937e098c56e37d2f0
commit: 1e4f6db614a310cc34d07ffbf031c76ea9581bcf gpiolib: support shared GPIOs in core subsystem code
config: x86_64-randconfig-161-20260410 (https://download.01.org/0day-ci/archive/20260411/202604110938.6uIVnQtT-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.4.0-5) 12.4.0
smatch: v0.5.0-9004-gb810ac53

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Fixes: 1e4f6db614a3 ("gpiolib: support shared GPIOs in core subsystem code")
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202604110938.6uIVnQtT-lkp@intel.com/

smatch warnings:
drivers/gpio/gpiolib.c:4732 gpiod_find_and_request() warn: 'desc' can also be NULL

vim +/desc +4732 drivers/gpio/gpiolib.c

c6ccc4dde17676 Hans de Goede       2025-09-20  4643  
0d776cfd5e5b55 Stephen Boyd        2024-02-22  4644  struct gpio_desc *gpiod_find_and_request(struct device *consumer,
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4645  					 struct fwnode_handle *fwnode,
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4646  					 const char *con_id,
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4647  					 unsigned int idx,
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4648  					 enum gpiod_flags flags,
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4649  					 const char *label,
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4650  					 bool platform_lookup_allowed)
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4651  {
ba2dc1cb549171 Hans de Goede       2022-12-29  4652  	unsigned long lookupflags = GPIO_LOOKUP_FLAGS_DEFAULT;
5c887b65bbd1a3 Andy Shevchenko     2024-03-25  4653  	const char *name = function_name_or_default(con_id);
e348544f7994d2 Bartosz Golaszewski 2024-01-19  4654  	/*
e348544f7994d2 Bartosz Golaszewski 2024-01-19  4655  	 * scoped_guard() is implemented as a for loop, meaning static
e348544f7994d2 Bartosz Golaszewski 2024-01-19  4656  	 * analyzers will complain about these two not being initialized.
e348544f7994d2 Bartosz Golaszewski 2024-01-19  4657  	 */
e348544f7994d2 Bartosz Golaszewski 2024-01-19  4658  	struct gpio_desc *desc = NULL;
e348544f7994d2 Bartosz Golaszewski 2024-01-19  4659  	int ret = 0;
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4660  
e348544f7994d2 Bartosz Golaszewski 2024-01-19  4661  	scoped_guard(srcu, &gpio_devices_srcu) {
c6ccc4dde17676 Hans de Goede       2025-09-20  4662  		desc = gpiod_fwnode_lookup(fwnode, consumer, con_id, idx,
e348544f7994d2 Bartosz Golaszewski 2024-01-19  4663  					   &flags, &lookupflags);
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4664  		if (!IS_ERR_OR_NULL(desc) &&

Imagine desc is NULL

1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4665  		    test_bit(GPIOD_FLAG_SHARED, &desc->flags)) {
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4666  			/*
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4667  			 * We're dealing with a GPIO shared by multiple
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4668  			 * consumers. This is the moment to add the machine
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4669  			 * lookup table for the proxy device as previously
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4670  			 * we only knew the consumer's fwnode.
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4671  			 */
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4672  			ret = gpio_shared_add_proxy_lookup(consumer, lookupflags);
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4673  			if (ret)
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4674  				return ERR_PTR(ret);
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4675  
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4676  			/* Trigger platform lookup for shared GPIO proxy. */
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4677  			desc = ERR_PTR(-ENOENT);
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4678  			/* Trigger it even for fwnode-only gpiod_get(). */
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4679  			platform_lookup_allowed = true;
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4680  		}
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4681  
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4682  		if (gpiod_not_found(desc) && platform_lookup_allowed) {
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4683  			/*
e348544f7994d2 Bartosz Golaszewski 2024-01-19  4684  			 * Either we are not using DT or ACPI, or their lookup
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4685  			 * did not return a result or this is a shared GPIO. In
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4686  			 * that case, use platform lookup as a fallback.
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4687  			 */
e348544f7994d2 Bartosz Golaszewski 2024-01-19  4688  			dev_dbg(consumer,
e348544f7994d2 Bartosz Golaszewski 2024-01-19  4689  				"using lookup tables for GPIO lookup\n");
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4690  			desc = gpiod_find(consumer, con_id, idx, &lookupflags);
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4691  		}
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4692  
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4693  		if (IS_ERR(desc)) {
5c887b65bbd1a3 Andy Shevchenko     2024-03-25  4694  			dev_dbg(consumer, "No GPIO consumer %s found\n", name);
0eadd36d912374 Dmitry Torokhov     2022-09-03  4695  			return desc;
0eadd36d912374 Dmitry Torokhov     2022-09-03  4696  		}
0eadd36d912374 Dmitry Torokhov     2022-09-03  4697  
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4698  		/*
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4699  		 * If a connection label was passed use that, else attempt to use
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4700  		 * the device name as label
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4701  		 */
0eadd36d912374 Dmitry Torokhov     2022-09-03  4702  		ret = gpiod_request(desc, label);
                                                                                    ^^^^
This would crash.  The zero day bot doesn't do cross function
analysis so it can't detect it.

e348544f7994d2 Bartosz Golaszewski 2024-01-19  4703  	}
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4704  	if (ret) {
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4705  		if (!(ret == -EBUSY && flags & GPIOD_FLAGS_BIT_NONEXCLUSIVE))
0eadd36d912374 Dmitry Torokhov     2022-09-03  4706  			return ERR_PTR(ret);
0eadd36d912374 Dmitry Torokhov     2022-09-03  4707  
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4708  		/*
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4709  		 * This happens when there are several consumers for the same
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4710  		 * GPIO line: we just return here without further
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4711  		 * initialization. It's a hack introduced long ago to support
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4712  		 * fixed regulators. We now have a better solution with
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4713  		 * automated scanning where affected platforms just need to
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4714  		 * select the provided Kconfig option.
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4715  		 *
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4716  		 * FIXME: Remove the GPIOD_FLAGS_BIT_NONEXCLUSIVE flag after
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4717  		 * making sure all platforms use the new mechanism.
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4718  		 */
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4719  		dev_info(consumer,
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4720  			 "nonexclusive access to GPIO for %s, consider updating your code to using gpio-shared-proxy\n",
1e4f6db614a310 Bartosz Golaszewski 2025-11-12  4721  			 name);
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4722  		return desc;
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4723  	}
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4724  
8eb1f71e7acca4 Dmitry Torokhov     2022-11-11  4725  	ret = gpiod_configure_flags(desc, con_id, lookupflags, flags);
0eadd36d912374 Dmitry Torokhov     2022-09-03  4726  	if (ret < 0) {
0eadd36d912374 Dmitry Torokhov     2022-09-03  4727  		gpiod_put(desc);
39c9049770f8b5 Peng Fan            2024-03-25  4728  		dev_err(consumer, "setup of GPIO %s failed: %d\n", name, ret);
0eadd36d912374 Dmitry Torokhov     2022-09-03  4729  		return ERR_PTR(ret);
0eadd36d912374 Dmitry Torokhov     2022-09-03  4730  	}
0eadd36d912374 Dmitry Torokhov     2022-09-03  4731  
ee194b12bf9a2f Bartosz Golaszewski 2024-10-04 @4732  	gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_REQUESTED);
0eadd36d912374 Dmitry Torokhov     2022-09-03  4733  
0eadd36d912374 Dmitry Torokhov     2022-09-03  4734  	return desc;
0eadd36d912374 Dmitry Torokhov     2022-09-03  4735  }

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


                 reply	other threads:[~2026-04-11  8:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202604110938.6uIVnQtT-lkp@intel.com \
    --to=error27@gmail.com \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=oe-kbuild@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®