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 06995D513 for ; Wed, 6 Sep 2023 14:16:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694009768; x=1725545768; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=0VcmV16fT8VmJAsdObBcJuWeG66DH8vv5hB7iUtf9Fk=; b=fGj3+XE3PY+c0erhYfI3dcqyeD0Q4QnU5AbCOunuXLoFv1K+AenkYkt7 03nTj6TshfqAy9pAjP9q1ui32ap1raZYYPwxBadqHWpRTRfai65nSptdB U431yd5Ex3E3bWRZnwcMVI8MZuuplidQo3BHzzZTQtBKEGy/uzImFAd2V Bo7Um3uk/h/s8rCx+vNk0+Fuqx55r0id8ouIA0kH0S02gKKdyo9k7E116 Mca6T+wjRcPMdr6rK/slE/LkEQ1y3IOlCjkI5HugujdwKoKQofZHxt7IW fNeVWS1pgvGgdu6/ABT72wGUH2gE2m3SmkYK8Z4dyd3XooiSSkJUcdOAE g==; X-IronPort-AV: E=McAfee;i="6600,9927,10825"; a="441051164" X-IronPort-AV: E=Sophos;i="6.02,232,1688454000"; d="scan'208";a="441051164" 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:16:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10825"; a="735072513" X-IronPort-AV: E=Sophos;i="6.02,232,1688454000"; d="scan'208";a="735072513" 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:16:03 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1qdtK3-006xcz-1V; Wed, 06 Sep 2023 17:15:59 +0300 Date: Wed, 6 Sep 2023 17:15:59 +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 04/21] gpiolib: provide gpio_device_get_desc() Message-ID: References: <20230905185309.131295-1-brgl@bgdev.pl> <20230905185309.131295-5-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-5-brgl@bgdev.pl> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo On Tue, Sep 05, 2023 at 08:52:52PM +0200, Bartosz Golaszewski wrote: > From: Bartosz Golaszewski > > Getting the GPIO descriptor directly from the gpio_chip struct is > dangerous as we don't take the reference to the underlying GPIO device. > In order to start working towards removing gpiochip_get_desc(), let's > provide a safer variant that works with an existing reference to struct > gpio_device. ... > +/** > + * gpio_device_get_desc() - get the GPIO descriptor corresponding to the given > + * hardware number for this GPIO device > + * @gdev: GPIO device to get the descriptor from > + * @hwnum: hardware number of the GPIO for this chip > + * > + * Returns: > + * A pointer to the GPIO descriptor or ``ERR_PTR(-EINVAL)`` if no GPIO exists The known constants can be referenced as %EINVAL. > + * in the given chip for the specified hardware number or ``ERR_PTR(-ENODEV)`` Ditto. > + * if the underlying chip already vanished. > + * > + * The reference count of struct gpio_device is *NOT* increased like when the > + * GPIO is being requested for exclusive usage. It's up to the caller to make > + * sure the GPIO device will stay alive together with the descriptor returned > + * by this function. > + */ -- With Best Regards, Andy Shevchenko