From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) (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 B7B5D613D for ; Wed, 6 Sep 2023 14:10:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694009427; x=1725545427; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=F7bl2h3DX3KJUesLeL2e/fpx9L5jnQCY/nK4NgE/LN8=; b=g3TfX+F5c9xs045JV9UkPGwPcOsj25+u2hqakhIJSlX5rsF/Xnj+2PbX GFOUeqZxs1Omg3vIbqQoir+ARc9lysQGgTbH1lgVFKuzr2wIE3LQF5Dkl LVPw/mEiJWCmdAR4HCu/aP9PXgiWO/3JSdpmPo/OaqRJcAyB+/2dFLsy4 fJ+zadFSrAZsoP2M8E4LWE7t6OvVY9G7h+fg3Z8loUTRNpqBR2VRVWPRh gKhXFt91pM8pzQFuyWtfVd3rHmUWpC0yGL3FdxgGlD8yWVFGfkUdypJ9K EQfqvoL8PafH9Q1XCCFqblVCAkFqmy9VY3mDMUPokCMjvYcGcMiit++O3 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10825"; a="441049793" X-IronPort-AV: E=Sophos;i="6.02,232,1688454000"; d="scan'208";a="441049793" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2023 07:10:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10825"; a="735068521" X-IronPort-AV: E=Sophos;i="6.02,232,1688454000"; d="scan'208";a="735068521" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga007.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2023 07:10:21 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1qdtEY-006xYP-12; Wed, 06 Sep 2023 17:10:18 +0300 Date: Wed, 6 Sep 2023 17:10:18 +0300 From: Andy Shevchenko To: Bartosz Golaszewski Cc: Aaro Koskinen , Janusz Krzysztofik , Tony Lindgren , Russell King , Mika Westerberg , Linus Walleij , Dipen Patel , Thierry Reding , Jonathan Hunter , Hans de Goede , Mark Gross , linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org, timestamp@lists.linux.dev, linux-tegra@vger.kernel.org, platform-driver-x86@vger.kernel.org, Bartosz Golaszewski Subject: Re: [PATCH 02/21] gpiolib: provide gpio_device_find() Message-ID: References: <20230905185309.131295-1-brgl@bgdev.pl> <20230905185309.131295-3-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: timestamp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230905185309.131295-3-brgl@bgdev.pl> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo On Tue, Sep 05, 2023 at 08:52:50PM +0200, Bartosz Golaszewski wrote: > From: Bartosz Golaszewski > > gpiochip_find() is wrong and its kernel doc is misleading as the > function doesn't return a reference to the gpio_chip but just a raw > pointer. The chip itself is not guaranteed to stay alive, in fact it can > be deleted at any point. Also: other than GPIO drivers themselves, > nobody else has any business accessing gpio_chip structs. > > Provide a new gpio_device_find() function that returns a real reference > to the opaque gpio_device structure that is guaranteed to stay alive for > as long as there are active users of it. ... > +/** > + * gpio_device_find() - find a specific GPIO device > + * @data: data to pass to match function > + * @match: Callback function to check gpio_chip > + * Returns: > + * New reference to struct gpio_device. I believe this is wrong location of the Return section. AFAIU how kernel doc uses section markers, this entire description becomes a Return(s) section. Have you tried to render man/html/pdf and see this? > + * Similar to bus_find_device(). It returns a reference to a gpio_device as > + * determined by a user supplied @match callback. The callback should return > + * 0 if the device doesn't match and non-zero if it does. If the callback > + * returns non-zero, this function will return to the caller and not iterate > + * over any more gpio_devices. > + * > + * The callback takes the GPIO chip structure as argument. During the execution > + * of the callback function the chip is protected from being freed. TODO: This > + * actually has yet to be implemented. > + * > + * If the function returns non-NULL, the returned reference must be freed by > + * the caller using gpio_device_put(). > + */ > +struct gpio_device *gpio_device_find(void *data, > + int (*match)(struct gpio_chip *gc, > + void *data)) One line? Or maybe a type for it? (gpio_match_fn, for example) > +{ > + struct gpio_device *gdev; > + > + guard(spinlock_irqsave)(&gpio_lock); > + > + list_for_each_entry(gdev, &gpio_devices, list) { > + if (gdev->chip && match(gdev->chip, data)) > + return gpio_device_get(gdev); > + } > + > + return NULL; > +} ... > +struct gpio_device *gpio_device_find(void *data, > + int (*match)(struct gpio_chip *gc, > + void *data)); Ditto. -- With Best Regards, Andy Shevchenko