From patchwork Mon Aug 19 13:22:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13768372 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 DC0B617554A; Mon, 19 Aug 2024 13:25:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724073928; cv=none; b=Sh1ELrDzboF/g+dYhdtqgwPUGF5798R/kykOWgq3cmgWmljwgU99YeJe5CyVM+qEzL+B8zKbQbnw0d57Xupfxt9igu2Gyqu5goaF0VaWMsLay9+TXawncyYu7SEG1cWNsCq87V4q7KetWqGhHunWDDzRjSA+iFojw36fHRy7QJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724073928; c=relaxed/simple; bh=MjquhYEVqBOB758biJCcHGoD0iH6FoBsUzxobOaKxQs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tZpT7X17kITEVIJ7IKWz9wY9yq3/t5UN8ll+07MhOZ+3bn574TOjPAH3VW2B8P8MPL3Q+Ic9XedlaNESumQK/+2+BCRDRjQELLnph7GUsJIXETDgNAnpBMQWYFx1tesmwu2QDyLsGHNtqvVfMRpXyMRBJCNz71VRfr88XHxv/+A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=FFh769ZY; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="FFh769ZY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724073927; x=1755609927; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MjquhYEVqBOB758biJCcHGoD0iH6FoBsUzxobOaKxQs=; b=FFh769ZYRpf8r+YbaCXaZlouKlsVXdFPCvfYwZqensNROXQE9AEoHTLd RH2Qt60Fc7DZcbMqU3xQNh1BHX10gu0JuqY7l8783HXtuoElDiBVkn7jA +f3ZldFXWm8DRc2JAiySCtrSbNTwwHHKJkPC1+g5Mlc22wGphSDW6ufOt FvnDK8YNJ0TIDA/CbpUbymRcCxC6ix13HnQTwnHb5gthuLj+eLXNb3cg7 zJ27WD52Aofh2+x5zzOqdPyt5u2l8GR9qAgmfUtOAVm2gKJocyrQJXeSE YgNzq8CBVCsM4W3rk/EvOqv68TO7r8Oef95/5gcU+cB5ipmmEWL2xnCq7 Q==; X-CSE-ConnectionGUID: hB9vcjwoTq+ZrDTiaFTbcw== X-CSE-MsgGUID: rJT3pyJdRLSQLTIhhU3R4Q== X-IronPort-AV: E=McAfee;i="6700,10204,11169"; a="22462704" X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="22462704" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2024 06:25:05 -0700 X-CSE-ConnectionGUID: 6vf8TilSSWW8DumG35lcEw== X-CSE-MsgGUID: zEdpsENLTX2hXxiZADmf3A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="64531826" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa003.fm.intel.com with ESMTP; 19 Aug 2024 06:25:02 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id D05BF213; Mon, 19 Aug 2024 16:25:01 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mika Westerberg , Linus Walleij , Bartosz Golaszewski Subject: [PATCH v1 1/5] gpiolib: Introduce for_each_gpio_property_name() helper Date: Mon, 19 Aug 2024 16:22:43 +0300 Message-ID: <20240819132458.208677-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20240819132458.208677-1-andriy.shevchenko@linux.intel.com> References: <20240819132458.208677-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Introduce a helper macro for_each_gpio_property_name(). With that in place, update users. This, in particular, will help making the following simplifications easier. Signed-off-by: Andy Shevchenko --- drivers/gpio/gpiolib-acpi.c | 21 ++------------------- drivers/gpio/gpiolib-of.c | 25 ++++--------------------- drivers/gpio/gpiolib.h | 13 +++++++++++++ 3 files changed, 19 insertions(+), 40 deletions(-) diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c index 70f029de63e6..d2fb69d227f4 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c @@ -983,18 +983,9 @@ __acpi_find_gpio(struct fwnode_handle *fwnode, const char *con_id, unsigned int struct acpi_device *adev = to_acpi_device_node(fwnode); struct gpio_desc *desc; char propname[32]; - int i; /* Try first from _DSD */ - for (i = 0; i < gpio_suffix_count; i++) { - if (con_id) { - snprintf(propname, sizeof(propname), "%s-%s", - con_id, gpio_suffixes[i]); - } else { - snprintf(propname, sizeof(propname), "%s", - gpio_suffixes[i]); - } - + for_each_gpio_property_name(propname, con_id) { if (adev) desc = acpi_get_gpiod_by_index(adev, propname, idx, info); @@ -1461,17 +1452,9 @@ int acpi_gpio_count(const struct fwnode_handle *fwnode, const char *con_id) int count = -ENOENT; int ret; char propname[32]; - unsigned int i; /* Try first from _DSD */ - for (i = 0; i < gpio_suffix_count; i++) { - if (con_id) - snprintf(propname, sizeof(propname), "%s-%s", - con_id, gpio_suffixes[i]); - else - snprintf(propname, sizeof(propname), "%s", - gpio_suffixes[i]); - + for_each_gpio_property_name(propname, con_id) { ret = acpi_dev_get_property(adev, propname, ACPI_TYPE_ANY, &obj); if (ret == 0) { if (obj->type == ACPI_TYPE_LOCAL_REFERENCE) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 006218cf9fc6..da4cab615013 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -105,20 +105,12 @@ int of_gpio_count(const struct fwnode_handle *fwnode, const char *con_id) const struct device_node *np = to_of_node(fwnode); int ret; char propname[32]; - unsigned int i; ret = of_gpio_spi_cs_get_count(np, con_id); if (ret > 0) return ret; - for (i = 0; i < gpio_suffix_count; i++) { - if (con_id) - snprintf(propname, sizeof(propname), "%s-%s", - con_id, gpio_suffixes[i]); - else - snprintf(propname, sizeof(propname), "%s", - gpio_suffixes[i]); - + for_each_gpio_property_name(propname, con_id) { ret = of_gpio_named_count(np, propname); if (ret > 0) break; @@ -696,23 +688,14 @@ static const of_find_gpio_quirk of_find_gpio_quirks[] = { struct gpio_desc *of_find_gpio(struct device_node *np, const char *con_id, unsigned int idx, unsigned long *flags) { - char prop_name[32]; /* 32 is max size of property name */ + char propname[32]; /* 32 is max size of property name */ enum of_gpio_flags of_flags; const of_find_gpio_quirk *q; struct gpio_desc *desc; - unsigned int i; /* Try GPIO property "foo-gpios" and "foo-gpio" */ - for (i = 0; i < gpio_suffix_count; i++) { - if (con_id) - snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id, - gpio_suffixes[i]); - else - snprintf(prop_name, sizeof(prop_name), "%s", - gpio_suffixes[i]); - - desc = of_get_named_gpiod_flags(np, prop_name, idx, &of_flags); - + for_each_gpio_property_name(propname, con_id) { + desc = of_get_named_gpiod_flags(np, propname, idx, &of_flags); if (!gpiod_not_found(desc)) break; } diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 5b545fd7b2c6..d38e83d82796 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -93,6 +93,19 @@ static inline struct gpio_device *to_gpio_device(struct device *dev) extern const char *const gpio_suffixes[]; extern const size_t gpio_suffix_count; +#define for_each_gpio_property_name(propname, con_id) \ + for (unsigned int __i = 0; \ + __i < gpio_suffix_count && ({ \ + const char *__gs = gpio_suffixes[__i]; \ + \ + if (con_id) \ + snprintf(propname, sizeof(propname), "%s-%s", con_id, __gs); \ + else \ + snprintf(propname, sizeof(propname), "%s", __gs); \ + 1; \ + }); \ + __i++) + /** * struct gpio_array - Opaque descriptor for a structure of GPIO array attributes * From patchwork Mon Aug 19 13:22:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13768368 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (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 14A6F16BE27; Mon, 19 Aug 2024 13:25:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724073910; cv=none; b=kRbBhG5phI1ouagmI4dxcaW5HwWh2mflobLx3fbyI3zJ6/679ZOs/6OL68IS5su0Zx6/dm8XXKpVgW1slX27jQSPusi8uzT3c1lMLNZJTCgIbWiCXfiobj878+nLF77zr6phf9xJFouOkIM131Mv5lzllkKcNXZ+k8/voxkrYWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724073910; c=relaxed/simple; bh=hLCbDRbO3vEot9Et5IQ5IhvldkSR77khW+PBp6rjsHc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gpdzsiBQx5F/3w+IccBmYk4uhopUHZKEqnWt6susqBSimHNR1psGdciuz0rUhXnMI1OEeoq/35FzJ8O8ONfGeBhnV3ByQdWmsKJLu/WmbwIz6R+Z1j0ZujQvbB+n/znCRCrA8XGQu18sfCTKfslInLSU/IxJcIhH1ZRHXeNoyp4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=RS+OQT1r; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RS+OQT1r" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724073909; x=1755609909; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hLCbDRbO3vEot9Et5IQ5IhvldkSR77khW+PBp6rjsHc=; b=RS+OQT1rx1uaWx7+MXRphZ8X5jUtu/863Ep7B6/V1GczratwOdT2KSxB SoSGXfXAGVWJnX37ZcGzrPdgAc+UheFTo94rzbIWJifkoLbsKdgy+l82l ahcNlekihWqc2lCyQyNSPgjKH1Gi37/uZYpwzrBdSU/OmesR/pAlRq1LH CyK0avq1fhs9wH+0RiiO0GuPD7uJ7qRo17nwYa23ztVRIlIcaJqEGP9oW 0FQtTBlugKtxJXbDGwRj+Z2LsVzGi8wnYY5zc2nTBQWhwiwC28v+NDGsm wsglbD5MMLr5gwyPrxfft7KruLoNg9uUtqJ9R67rvyGBq2dk9LVpRVgti w==; X-CSE-ConnectionGUID: NQNrUPwvRsOOKk/fNrjCxw== X-CSE-MsgGUID: IgQpJQt0Q0WvyeizQ6gmUw== X-IronPort-AV: E=McAfee;i="6700,10204,11169"; a="47718618" X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="47718618" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2024 06:25:08 -0700 X-CSE-ConnectionGUID: fzK9yMD2SFGxB9XEqFbMSg== X-CSE-MsgGUID: /rvbQcs/S2iTvb7SBr2HNQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="60211764" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa010.jf.intel.com with ESMTP; 19 Aug 2024 06:25:03 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id E04A4562; Mon, 19 Aug 2024 16:25:01 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mika Westerberg , Linus Walleij , Bartosz Golaszewski Subject: [PATCH v1 2/5] gpiolib: swnode: Unify return code variable name Date: Mon, 19 Aug 2024 16:22:44 +0300 Message-ID: <20240819132458.208677-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20240819132458.208677-1-andriy.shevchenko@linux.intel.com> References: <20240819132458.208677-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In one case 'ret' is used in the other 'error'. Make the latter use the former, i.e. 'ret'. Signed-off-by: Andy Shevchenko --- drivers/gpio/gpiolib-swnode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpiolib-swnode.c b/drivers/gpio/gpiolib-swnode.c index 0578e1be159f..e72576908d8f 100644 --- a/drivers/gpio/gpiolib-swnode.c +++ b/drivers/gpio/gpiolib-swnode.c @@ -67,7 +67,7 @@ struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode, struct fwnode_reference_args args; struct gpio_desc *desc; char propname[32]; /* 32 is max size of property name */ - int error; + int ret; swnode = to_software_node(fwnode); if (!swnode) @@ -79,11 +79,11 @@ struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode, * We expect all swnode-described GPIOs have GPIO number and * polarity arguments, hence nargs is set to 2. */ - error = fwnode_property_get_reference_args(fwnode, propname, NULL, 2, idx, &args); - if (error) { + ret = fwnode_property_get_reference_args(fwnode, propname, NULL, 2, idx, &args); + if (ret) { pr_debug("%s: can't parse '%s' property of node '%pfwP[%d]'\n", __func__, propname, fwnode, idx); - return ERR_PTR(error); + return ERR_PTR(ret); } struct gpio_device *gdev __free(gpio_device_put) = From patchwork Mon Aug 19 13:22:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13768371 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 9524E16CD2B; Mon, 19 Aug 2024 13:25:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724073928; cv=none; b=PG714vw9syVWDmc6HZXSLHkhJ8clXhoQ/Q/77iwEu74+abCS6N5/9df9w7n2SwCobr/Fh9sd0dBLXwCxCDhzTeQ/oLZ/wkUO+DxLehTvES0SdkaWnoksN2VOk1FKJJTzjnFQOyzWZ4CsOrUuJSg8tF7jdm9brrjSF4Vr1Urwusk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724073928; c=relaxed/simple; bh=+5ZWeQfq9pc8g+Da+jIQ//Boi20g3garQCTXou+6Uts=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c444oIgVDE40b0qv5D14/v3tlMQjBzOHjBOS9oBr1c/tIBOMg54HkVoLAfPcCBSuBEmRBMSpI83ViuBY1+ifyFD6FDLpCr3lAs2fH0PxQZe2AuGihhceVv50ppRCRggtBE35yARnvdTIBCVXmH4iY8Y83BEHc08VZzF42eBnrKw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ig0qMFJ1; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ig0qMFJ1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724073926; x=1755609926; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+5ZWeQfq9pc8g+Da+jIQ//Boi20g3garQCTXou+6Uts=; b=ig0qMFJ1hEnyDAOjG01AI083t/VCQ2JnEXpdrJOThs2RTmw5+A5NZGhD oEnb+Ub6rPfVGeRI+Q3wf+p6ktGoSo4mGW9MpBRuaE2rzzMBOG2QRm6rQ PS6apHRB1Zkne7VDw1IaJJRtDJfEoKeLMSA4jFESPxn8QFBeWAzpsbyPR /l4umqKaPeJDO+dFmsu9ArMyA+JhThxY4oTXSgUhjHqSKrxTH9UoDGjG/ bQqVmfKZIxb25C2lG1qVJ6Idy7pNfDAfl8LciUfUFH0SaJm5YScgFjpeG lCw8i1JOmpuzfwBu8rzB5RTvFUHVuk3p3s4RSBQhU27q5KGyH6IBBG92s g==; X-CSE-ConnectionGUID: jw+m/q7HTdaW9dK62P+Rgg== X-CSE-MsgGUID: TDfBjuDKSOGBfiVvLemA6A== X-IronPort-AV: E=McAfee;i="6700,10204,11169"; a="22462709" X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="22462709" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2024 06:25:05 -0700 X-CSE-ConnectionGUID: OYgQGcj8TU+ZqdCWUiD80g== X-CSE-MsgGUID: E1WrySN9QlmHec6dItHoSA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="64531827" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa003.fm.intel.com with ESMTP; 19 Aug 2024 06:25:02 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id E600751C; Mon, 19 Aug 2024 16:25:01 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mika Westerberg , Linus Walleij , Bartosz Golaszewski Subject: [PATCH v1 3/5] gpiolib: swnode: Introduce swnode_gpio_get_reference() helper Date: Mon, 19 Aug 2024 16:22:45 +0300 Message-ID: <20240819132458.208677-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20240819132458.208677-1-andriy.shevchenko@linux.intel.com> References: <20240819132458.208677-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Instead of the spreading simlar code over the file, introduce a helper. It also enforces the nargs validation for all GPIO software node APIs. Signed-off-by: Andy Shevchenko --- drivers/gpio/gpiolib-swnode.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpiolib-swnode.c b/drivers/gpio/gpiolib-swnode.c index e72576908d8f..8dd3c1a5dc55 100644 --- a/drivers/gpio/gpiolib-swnode.c +++ b/drivers/gpio/gpiolib-swnode.c @@ -59,6 +59,17 @@ static struct gpio_device *swnode_get_gpio_device(struct fwnode_handle *fwnode) return gdev ?: ERR_PTR(-EPROBE_DEFER); } +static int swnode_gpio_get_reference(const struct fwnode_handle *fwnode, + const char *propname, unsigned int idx, + struct fwnode_reference_args *args) +{ + /* + * We expect all swnode-described GPIOs have GPIO number and + * polarity arguments, hence nargs is set to 2. + */ + return fwnode_property_get_reference_args(fwnode, propname, NULL, 2, idx, args); +} + struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode, const char *con_id, unsigned int idx, unsigned long *flags) @@ -75,11 +86,7 @@ struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode, swnode_format_propname(con_id, propname, sizeof(propname)); - /* - * We expect all swnode-described GPIOs have GPIO number and - * polarity arguments, hence nargs is set to 2. - */ - ret = fwnode_property_get_reference_args(fwnode, propname, NULL, 2, idx, &args); + ret = swnode_gpio_get_reference(fwnode, propname, idx, &args); if (ret) { pr_debug("%s: can't parse '%s' property of node '%pfwP[%d]'\n", __func__, propname, fwnode, idx); @@ -128,8 +135,7 @@ int swnode_gpio_count(const struct fwnode_handle *fwnode, const char *con_id) * 1 or 2 entries. */ count = 0; - while (fwnode_property_get_reference_args(fwnode, propname, NULL, 0, - count, &args) == 0) { + while (swnode_gpio_get_reference(fwnode, propname, count, &args) == 0) { fwnode_handle_put(args.fwnode); count++; } From patchwork Mon Aug 19 13:22:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13768373 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 6F1DA175D4A; Mon, 19 Aug 2024 13:25:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724073930; cv=none; b=nQv55uSYpeGgIP6cSTjX+Z2JwToMQnIPgZtQTG+NTh3XlTw2VllkYAAMMIBnamtPKk2L4kIKnxNNM1NxAJhHAIdNh9Oz66RMVFXswNLjGf80+jKXuANk+bMToBnRcHDLWvHWNlTdNfY3bfF1ygOKS5ONYZsqXuyXZ1VQZUbO6Tw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724073930; c=relaxed/simple; bh=Q5D2GX1ner8moRAIJYBQ51PVa6YVDkS1fzjLA4jX5WA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SFfjwbm1N4ScJjMORVc+3ev92ymRTvFpBV5SmG3Yzf5Z4pxmmFr0++zJOMlDzr3BChbqfwiuUaZUBQstG18Gknjr3gKO8RgFw8XA9AJMNs+mCXTYrEmnE8A7ZgE5GB5KBMojA9bzeMHYuM7fUhkUuj4cxTe1ShaFy0tRyMdwiVY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=FlnXAabl; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="FlnXAabl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724073928; x=1755609928; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Q5D2GX1ner8moRAIJYBQ51PVa6YVDkS1fzjLA4jX5WA=; b=FlnXAablCm90Jl1YjbUj5RbyQzQPEqid2fvQCL3F+fArVkj1/+CWzNFA LuhdRVFUYhF4ah3ZCBnh9viZmF1eA29O8P3ADpY5EV3Dk1jty9q8D83aL /35nnutLIbJm6pbtacSNQpV9UCFX+pq3PqiltLiUB5Bt7+t5fiB4ZlGyT WykR4swGb9LlGpyZxdh6tg+kQfKlG08s8R9RxFWkCRcpo7IKcKDkRZ5Ru hWfnlnnj4W/jENSXtM++Q2jLK0XiVNbfdfFeOl8wYBrYJpT8bRWtMcxrw IgBNvmPvk+njCWmSdJs173FvwtM6w2RyYUbC8TijMx7t/2h8fwvJwI+sK A==; X-CSE-ConnectionGUID: Plo0/mCBRUyeR/joDBtt5Q== X-CSE-MsgGUID: ZWd3A1RRTpOQNbQma/m/XQ== X-IronPort-AV: E=McAfee;i="6700,10204,11169"; a="22462714" X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="22462714" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2024 06:25:06 -0700 X-CSE-ConnectionGUID: sM2BnpinS2ilSuwNje331g== X-CSE-MsgGUID: HEK6gPpEQDeqsWvBSGZdPA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="64531829" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa003.fm.intel.com with ESMTP; 19 Aug 2024 06:25:03 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 01515644; Mon, 19 Aug 2024 16:25:01 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mika Westerberg , Linus Walleij , Bartosz Golaszewski Subject: [PATCH v1 4/5] gpiolib: swnode: Make use of for_each_gpio_property_name() Date: Mon, 19 Aug 2024 16:22:46 +0300 Message-ID: <20240819132458.208677-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20240819132458.208677-1-andriy.shevchenko@linux.intel.com> References: <20240819132458.208677-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For the sake of unification and easier maintenance replace swnode_format_propname() call with for_each_gpio_property_name() for-loop. Signed-off-by: Andy Shevchenko --- drivers/gpio/gpiolib-swnode.c | 38 +++++++++++++---------------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/drivers/gpio/gpiolib-swnode.c b/drivers/gpio/gpiolib-swnode.c index 8dd3c1a5dc55..efcb4ae6eb26 100644 --- a/drivers/gpio/gpiolib-swnode.c +++ b/drivers/gpio/gpiolib-swnode.c @@ -24,20 +24,6 @@ #define GPIOLIB_SWNODE_UNDEFINED_NAME "swnode-gpio-undefined" -static void swnode_format_propname(const char *con_id, char *propname, - size_t max_size) -{ - /* - * NOTE: We do not need to try both -gpios and -gpio suffixes, - * as, unlike OF and ACPI, we can fix software nodes to conform - * to the proper binding. - */ - if (con_id) - snprintf(propname, max_size, "%s-gpios", con_id); - else - strscpy(propname, "gpios", max_size); -} - static struct gpio_device *swnode_get_gpio_device(struct fwnode_handle *fwnode) { const struct software_node *gdev_node; @@ -84,9 +70,11 @@ struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode, if (!swnode) return ERR_PTR(-EINVAL); - swnode_format_propname(con_id, propname, sizeof(propname)); - - ret = swnode_gpio_get_reference(fwnode, propname, idx, &args); + for_each_gpio_property_name(propname, con_id) { + ret = swnode_gpio_get_reference(fwnode, propname, idx, &args); + if (ret == 0) + break; + } if (ret) { pr_debug("%s: can't parse '%s' property of node '%pfwP[%d]'\n", __func__, propname, fwnode, idx); @@ -128,19 +116,21 @@ int swnode_gpio_count(const struct fwnode_handle *fwnode, const char *con_id) char propname[32]; int count; - swnode_format_propname(con_id, propname, sizeof(propname)); - /* * This is not very efficient, but GPIO lists usually have only * 1 or 2 entries. */ - count = 0; - while (swnode_gpio_get_reference(fwnode, propname, count, &args) == 0) { - fwnode_handle_put(args.fwnode); - count++; + for_each_gpio_property_name(propname, con_id) { + count = 0; + while (swnode_gpio_get_reference(fwnode, propname, count, &args) == 0) { + fwnode_handle_put(args.fwnode); + count++; + } + if (count) + return count; } - return count ?: -ENOENT; + return -ENOENT; } #if IS_ENABLED(CONFIG_GPIO_SWNODE_UNDEFINED) From patchwork Mon Aug 19 13:22:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13768369 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (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 11D5A16CD0F; Mon, 19 Aug 2024 13:25:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724073912; cv=none; b=uokFwga4YoQgSejWyicMbileEL1veWyBylXwNIigDZMDZ9nkhzomUlsded5YPz9mezBoW8oyh5oEg9mrhNdlxzpEi+VWUo6PfdLItU9ASK4Eqy4GQTw0tDiQkIPE2zyRB8hQJIWfkMObbBn8DhEMKsBvSQcFiLoy2FYeCa4C3aU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724073912; c=relaxed/simple; bh=DZkkfksY4RuNkDc6eYi1tB+4DQHIyYH/G6/B6BAG23U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TXjKZ5eHEDVhP5sS+CKm81S3ImqqKgXw1POES+eVbIJFMJCNe1Vw78SZAiEBPYmNhQY02zb6+swLoLMYHatfH2Dz4OhGr76QnaBql/4sdvqwfr/Y5UkX5d1NYUqI62xRdZmSh5OR0mtJYDHPMq0wUTo+1ljYGP4gRNhMUjsTln4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=iGiciWtA; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="iGiciWtA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724073911; x=1755609911; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DZkkfksY4RuNkDc6eYi1tB+4DQHIyYH/G6/B6BAG23U=; b=iGiciWtAU59MmeMrcI4qVDXciaPbsuRGAW1rYh6mSL1wZQgMWGKH8pMX x/e/qZV9oSy7qpvhpctOBA7UuFpYgm1YIBqgGjAXtmr6VFvIilht1iBQi 1Vzsm5GFMn4x6hKPdnqN5TVt+yuu+94C1TSQ2ZV5qOa5dAR8swylqqq9D A9qrB3d28rB3ZtiHgOYXuCulVZYmt1j97630Jg4+/qPrOBZf9pQ1yfPmw VlTfnpuNEknfU2WbPRexPDTd70N32F40dT7WNWHfq7n/YP1sOPtlBgmfB lbqoohiEzyprGqCx1xYPMFIgJU0M8497e18NFzxW4wSIGub9DCuG2bofQ Q==; X-CSE-ConnectionGUID: eQv7BSYzQEKOioGiwo1Kug== X-CSE-MsgGUID: /LqO+1WsTeybEiw+cg8m4g== X-IronPort-AV: E=McAfee;i="6700,10204,11169"; a="47718622" X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="47718622" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2024 06:25:08 -0700 X-CSE-ConnectionGUID: A/VFWTMUQuCboJ6EUCe00Q== X-CSE-MsgGUID: Hz4GXzlMQD6U+8tWyjZMKQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="60211807" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa010.jf.intel.com with ESMTP; 19 Aug 2024 06:25:06 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 101A7719; Mon, 19 Aug 2024 16:25:02 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mika Westerberg , Linus Walleij , Bartosz Golaszewski Subject: [PATCH v1 5/5] gpiolib: Replace gpio_suffix_count with NULL-terminated array Date: Mon, 19 Aug 2024 16:22:47 +0300 Message-ID: <20240819132458.208677-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20240819132458.208677-1-andriy.shevchenko@linux.intel.com> References: <20240819132458.208677-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There is no need to have and export the count variable for the array in question. Instead, make it NULL-terminated. Signed-off-by: Andy Shevchenko --- drivers/gpio/gpiolib.c | 3 +-- drivers/gpio/gpiolib.h | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 7f6060c5b5e0..08fdf06a258f 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -91,8 +91,7 @@ DEFINE_STATIC_SRCU(gpio_devices_srcu); static DEFINE_MUTEX(gpio_machine_hogs_mutex); static LIST_HEAD(gpio_machine_hogs); -const char *const gpio_suffixes[] = { "gpios", "gpio" }; -const size_t gpio_suffix_count = ARRAY_SIZE(gpio_suffixes); +const char *const gpio_suffixes[] = { "gpios", "gpio", NULL }; static void gpiochip_free_hogs(struct gpio_chip *gc); static int gpiochip_add_irqchip(struct gpio_chip *gc, diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index d38e83d82796..3c7e80f8a0c5 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -89,14 +89,13 @@ static inline struct gpio_device *to_gpio_device(struct device *dev) return container_of(dev, struct gpio_device, dev); } -/* gpio suffixes used for ACPI and device tree lookup */ +/* GPIO suffixes used for ACPI and device tree lookup */ extern const char *const gpio_suffixes[]; -extern const size_t gpio_suffix_count; #define for_each_gpio_property_name(propname, con_id) \ - for (unsigned int __i = 0; \ - __i < gpio_suffix_count && ({ \ - const char *__gs = gpio_suffixes[__i]; \ + for (const char * const *__suffixes = gpio_suffixes; \ + *__suffixes && ({ \ + const char *__gs = *__suffixes; \ \ if (con_id) \ snprintf(propname, sizeof(propname), "%s-%s", con_id, __gs); \ @@ -104,7 +103,7 @@ extern const size_t gpio_suffix_count; snprintf(propname, sizeof(propname), "%s", __gs); \ 1; \ }); \ - __i++) + __suffixes++) /** * struct gpio_array - Opaque descriptor for a structure of GPIO array attributes