From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ADFAFEE14A5 for ; Wed, 6 Sep 2023 15:16:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SwHGHYh56XhEqoVU+DxGft7nzC5R5qWEJsWLQaUuHnQ=; b=SY6aSIeh8fA5tw DwxrTxLPNseAfY7QU6hiNv3wF0ZNkIurj1tU9wPuC0l3hAbeIIDeAMR3ZCwvDBHbQ/Ob8kmy+6o3o IglapDN6WtCD8g1w7U0qxgp63iN7qWZDhLSosMhhCnUnrBS4BQxq9YgS1esTIgGSM55IaUwI5FRbM /3X0KVUHfW3Ffo2v2GJ+aSm4eH0ldHm1JMKFGkA/ce/pVgURMvApNNZ1nkjaMG1t961HAr75CMYCY 62FkYEFm9T5Sc/qofQQ4/bst9XWdrtvEKtcFck+zxZSC4uf++WTjLpIb+7FkX4AwutUte5tedxqHk wdiRXr72sqRxIfPAT58A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qduGG-00ANSX-2L; Wed, 06 Sep 2023 15:16:08 +0000 Received: from mgamail.intel.com ([134.134.136.31]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qdtEi-00ABcE-0Z for linux-arm-kernel@lists.infradead.org; Wed, 06 Sep 2023 14:10:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694009428; x=1725545428; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=F7bl2h3DX3KJUesLeL2e/fpx9L5jnQCY/nK4NgE/LN8=; b=gyIGjVc3Jo8axnyfeA5smHCNxZwr3i7z5ly14uxWuQxPDV2tW6VEXnPA dLUCDwzsPmTQHsmQa/ouoiaTicHeSzkSs12ZwYk8Hhfx2JNMOC4cYKi5i 3VjVfAShGBWPp6P4n6JfyXvG/Y72Myftp0fEkDYvARrny4LkpURyEAjMs 0btieE367WQD8MNOEt2CQi6BOPOx66Ea+oA1K7/jIzYpMMER8K2D56I/V YM/0qoJPdGl2RH0IeC6DxRZ7nOz15u0QNexopFSRpBTqodZsrVn3oasI+ g2ajEApQq90lSA9FEHhDEalFugiX4h+7nL1iF7hZ+gyfqD92GO6eXKzz5 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10825"; a="441049791" X-IronPort-AV: E=Sophos;i="6.02,232,1688454000"; d="scan'208";a="441049791" 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> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230905185309.131295-3-brgl@bgdev.pl> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230906_071028_257449_F52DDA41 X-CRM114-Status: GOOD ( 25.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel