From patchwork Mon Aug 19 14:28:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 820312 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.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 4201E170A3A; Mon, 19 Aug 2024 14:29:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724077796; cv=none; b=L48MlPc1TN6dTW2s8Rj/9UaAVpklUTp65jK0aqz3E6632/NqfJ93eyEOaY8wGPTMyTKDIAjecweLruvcrdzZuPLzzOIED/HTvdvLD+XkMqF0FeA2Y9c5TXeGZkoPkE+Py3ZuoGpLxRJ0yWoD7WEEa6VD6+hROcw2S/ADHyxvpn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724077796; c=relaxed/simple; bh=C5ACBFQpLuJg+E8NQQggc4sxL+G3zBv8J5W1Xd3/EE8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KY1P4WEi77uPTQOZN7dOtNMEMDKPb3Vwku89LybUB4UdQWnALkF29wr/IuDGeur2xTznFAg1cvr/OVKZ2UvxU4gCBVL48a/k24yjX2rPKtIlIeGDMZds4NZzBah1O5JuYy1ETA+I7FdJgMqo3QwactOgst9O8D5bx67CjE6XIhY= 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=eDNn3/XC; arc=none smtp.client-ip=192.198.163.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="eDNn3/XC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724077793; x=1755613793; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=C5ACBFQpLuJg+E8NQQggc4sxL+G3zBv8J5W1Xd3/EE8=; b=eDNn3/XC4ABuBcgLAm2j5VIHKcT6bdR6x1z0mAKV20eIpRPx75UzPrUL tRx4XS7DZgdVZSCW+yNXVVZR8Jhbia+QpBFzp0XiBSzw6Fqsf0FLbOTH1 pBDcFKPnyTWW+F5LOQ5/UG8Hj1WaK6P0FMVNsl0Y2d6Tm1FBvceO95XCy OvIhWCJ51iSH2bDT6kGPdQ1lnsss3OLDywsQs6DMcXZZ68UkQjlwx/dYp Ex2dm26ClZP09ddxdMD8kJq8MReW5elMMMAxt2VynSNichNmOUIgK+Hsz dKbunUvbOkIEv+v4uK/zZX1/yaF+rDRCsgitMBQJGelOM1Xi0giT0Y3SN Q==; X-CSE-ConnectionGUID: UhhUZH6bQYKTRk4XiraWHw== X-CSE-MsgGUID: TP0Us7F6Qzmxo3v8r7zDBw== X-IronPort-AV: E=McAfee;i="6700,10204,11169"; a="21873813" X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="21873813" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2024 07:29:52 -0700 X-CSE-ConnectionGUID: XDeB6+l6TzqxXwjYJatz4w== X-CSE-MsgGUID: BhpVxZ/ETmSJjQ6p5+421g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="65350560" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa004.jf.intel.com with ESMTP; 19 Aug 2024 07:29:51 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 2D498213; Mon, 19 Aug 2024 17:29:49 +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 v2 1/5] gpiolib: Introduce for_each_gpio_property_name() helper Date: Mon, 19 Aug 2024 17:28:56 +0300 Message-ID: <20240819142945.327808-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20240819142945.327808-1-andriy.shevchenko@linux.intel.com> References: <20240819142945.327808-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 69cd2be9c7f3..cf4b1f068bac 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c @@ -973,18 +973,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); @@ -1450,17 +1441,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 6683e531df52..92984f6d2aa8 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -97,20 +97,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; @@ -687,23 +679,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 4de0bf1a62d3..0271e747fb6e 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 14:28:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 821018 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (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 5ED90171E69; Mon, 19 Aug 2024 14:29:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724077795; cv=none; b=AqaYQUU/BIW/riMxDm1JsQzVcKK9GxCvSJ7Ys5rurxPSw9GvxX3962BuVsNqmhO9kM4ZCzIMVJMMt06T2E07OtEHYPzDnH1T9Ghj8hatA4izNcIfB+YuxF7QATNyzaYp01wlUMaJNPkboVZfDpIvWAyoFnfOLsCVb6+FVCM5Qhs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724077795; c=relaxed/simple; bh=dmKhPReYD4J99q0uHP9FDEoqkLnDOYZIsfRxqA+9vEc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bBf/Xzo1tKw2z5hzB0ECCCiMurxiUdfuECRX+dLkhbPyybZFjESL9NAsxWhrm/LyPH+Ru/EnF+PmXbxVl79S4Y+W9OT1P2/QbGE1+P++CZw7yPdoyTcI8NfJA4J4Ha84Rr0opFoUeLt+56FYu38hyOawYff12b8RZovLBFeucrg= 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=LtLRLm6b; arc=none smtp.client-ip=192.198.163.10 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="LtLRLm6b" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724077794; x=1755613794; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dmKhPReYD4J99q0uHP9FDEoqkLnDOYZIsfRxqA+9vEc=; b=LtLRLm6bS5sMEwWJVn2dD71Q6JJfYWp7FiYoB9bep8mPEtuzDEKuTvc4 hJxwq9gm9OOtLh/PWBad8lHyivtPrtfSOQdGMXqBN/MvNiD8CnCStnoNU nxYPx0A5HcC5iTfTaAzIVN4d8wiITbo7SjvNuGSJz/+Pdb/e1eB3YkLeO ncRqxQmylgM5lrRRRNbLXz8y+LZavRvPnA2+98NYggLsTrg5dBsiwKDkF eyJ7VopOT0rICVgsAWIKi4+kf3XRdXYrdSLJ+X6m9lrBAQOzGx2+NZ8Xc 5+7PMDTniv3Zzav30iGmgCm+htT0nTWwaf+6Qpge7BGtSo48TxoY+pZ+a g==; X-CSE-ConnectionGUID: EA7bml2LRw+D0cImCoAF7g== X-CSE-MsgGUID: PcKnHIqDR8mVrmdKPvxHzg== X-IronPort-AV: E=McAfee;i="6700,10204,11169"; a="33744482" X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="33744482" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2024 07:29:53 -0700 X-CSE-ConnectionGUID: cWTko2zsSySHfiu6rbz7rA== X-CSE-MsgGUID: fUdlcGbNQu6V+ySKIVw48w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="64783796" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa005.fm.intel.com with ESMTP; 19 Aug 2024 07:29:50 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 3C76751C; Mon, 19 Aug 2024 17:29:49 +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 v2 2/5] gpiolib: swnode: Unify return code variable name Date: Mon, 19 Aug 2024 17:28:57 +0300 Message-ID: <20240819142945.327808-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20240819142945.327808-1-andriy.shevchenko@linux.intel.com> References: <20240819142945.327808-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 cec1ab878af8..e7ba6cc73966 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 14:28:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 821016 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (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 595261741DC; Mon, 19 Aug 2024 14:29:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724077799; cv=none; b=Xo37jqNAMXakX7qFr/WgKrLVz0ps4rY1feoh74n4K4/aay6bsla7KtI4Z/GUyLEqGSRZoLA+LjdeSbyzSc3Fx7SqASfATo879wB00ZclbtMaoWmfuMuICYhb4ajH0c0mRHEYP5/XKv9PU3r+CuZfZnYqNh+ein5gwNwCHVnEAFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724077799; c=relaxed/simple; bh=rFuwdwcbQYp8sy5sHNy4OFa8J5BoSjowDcZF++YteB0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GSfmwq8KJfuUbI4mnbjOfnlcmy+WsZIZkZ2gXE+E0leBEofsFkZFLVmqnH6TPNM265AkWVmFZfS6tz7RLPTfaBbMsAJzRr1vV3TCSuuDKp0EshkolK0EGKtEjs8Ju1cnjywAK9TQfoXDfij4pCieDpXk/9qToF9mZvXTvfNASK8= 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=Z/jZa4U7; arc=none smtp.client-ip=192.198.163.10 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="Z/jZa4U7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724077798; x=1755613798; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rFuwdwcbQYp8sy5sHNy4OFa8J5BoSjowDcZF++YteB0=; b=Z/jZa4U7qKrEQEAZIq8tBewCE/GgEhSjdXo0BgB6OQUZ1yg+CGcvgMDu bNw13pBAgRr4jMW6vy3RXuXWCl8gn7cZGNN2jKrvLjkYm0+VecA7eVQVP OBn8zbZn+oa1ElV0JZixO3Yw88aH2Y6+nowkFYB4z9ihz2NM3d34rufty gfaRuSN2q9JxQBQcwlGB2vC4uQ2dQRIHfa+sJwPENBBm/ZkpObMQGOelF GsHFAybr3oJsyXdjckR546ZrYILttqayVO1b8rrSriGRfCptGMSNqhakk sLuexj+mOe2mlKZCsnS0Ubd85EzkVMd67IufCFRPeLUB6bPcYM6o8Cgfa Q==; X-CSE-ConnectionGUID: dUHzdR+jR7idL1cluImErQ== X-CSE-MsgGUID: nkQf8t19RA2vvJSKkWeMgQ== X-IronPort-AV: E=McAfee;i="6700,10204,11169"; a="33744485" X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="33744485" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2024 07:29:53 -0700 X-CSE-ConnectionGUID: h1FjunUMQgmIcbwYzZk/0A== X-CSE-MsgGUID: kmiOfzEQQLiS4F+RL2FwCg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="64783797" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa005.fm.intel.com with ESMTP; 19 Aug 2024 07:29:50 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 505A15CF; Mon, 19 Aug 2024 17:29:49 +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 v2 3/5] gpiolib: swnode: Introduce swnode_gpio_get_reference() helper Date: Mon, 19 Aug 2024 17:28:58 +0300 Message-ID: <20240819142945.327808-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20240819142945.327808-1-andriy.shevchenko@linux.intel.com> References: <20240819142945.327808-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 e7ba6cc73966..d5e58a9673b5 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 14:28:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 821017 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (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 7968C1714CA; Mon, 19 Aug 2024 14:29:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724077797; cv=none; b=kr0+5Y2L35p8d5xhLvzxDNoXvzSA8lR5Lq5H7mtSihk9r/UM7ELYYxJGrdgKjn3kjSN8gvSnwizW12n1J1UD/hlQM5aFWy1CDkUbIUsbb2m6dvZnLgEjWG8Wgkoix7xSKpJfpTLBNym8vEJKss5kKhuVIaJwJRDL/LTwheYa4Ao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724077797; c=relaxed/simple; bh=DXf/668hEJFBZCZunwJNVzH/sOB3Oy72nRMF+xG4+GA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M12dLwnBBcZVYRZFkC6weALQTZPFL0Z2AhgtbcAPBbbMyG90lCziSzrMuyijsa4hKF8sNe9roh/o4zV0ibzrcKE04errtpNN9+9OWXA7E+BrDt6scVJkeSCOA5yAkh9TneXC5268QTrC6ReL8s9oQCOY8fz4e9w3OwErrS9ZsKA= 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=D1dYFuA0; arc=none smtp.client-ip=192.198.163.10 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="D1dYFuA0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724077796; x=1755613796; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DXf/668hEJFBZCZunwJNVzH/sOB3Oy72nRMF+xG4+GA=; b=D1dYFuA0siPW1iqE5BPJ9Qj4ETP4Ul8dCIfCqLgf5WL6q5cVQoAVh/QY J+HystNQZauHqvOwiKrqru8D4EkKl0AanKivoQtYXCdKGrTTPhnQXcQJv a4N/VIsY3Y/22mOaYyiyYLDo3lHIo8aSwM9hBHYbRLQsQe1idQ+3y6zhB mDs4RHD3C0KHc7Utnppiw2Os1Uy7ZuBmYFUiEYKTYNqIDIo+ny7x3kuPM t7LHdfMXOl/XVZy0ZltQCt5XLK6rZpgD+O01MzG+5MdjuPSiJ74PHJkZW g+vC6AD3eTmOjKCABVypVm/9Px1MLvKbvmuAn8PxVyFLbhMB1Y9q1VjC5 g==; X-CSE-ConnectionGUID: j5evXee+Q0qGZG4NCjGMfQ== X-CSE-MsgGUID: zMMCPVFQTIqiVCBHx6+0iQ== X-IronPort-AV: E=McAfee;i="6700,10204,11169"; a="33744488" X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="33744488" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2024 07:29:53 -0700 X-CSE-ConnectionGUID: +rVE+JrdSz+xh3+O2E2nBQ== X-CSE-MsgGUID: CDQpmSeXS7SACr0ZKkSdoQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="64783795" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa005.fm.intel.com with ESMTP; 19 Aug 2024 07:29:50 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 5A32F562; Mon, 19 Aug 2024 17:29:49 +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 v2 4/5] gpiolib: swnode: Make use of for_each_gpio_property_name() Date: Mon, 19 Aug 2024 17:28:59 +0300 Message-ID: <20240819142945.327808-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20240819142945.327808-1-andriy.shevchenko@linux.intel.com> References: <20240819142945.327808-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 d5e58a9673b5..1a6f70671816 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 14:29:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 820310 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (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 A1566175562; Mon, 19 Aug 2024 14:29:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724077800; cv=none; b=Ot+tPSO0wmxp2LhabisNRGX95uSYCzAs2hGrhdxUdzdLOEn17Bk3pUk6yY6j1KgJsVa4a5T30WxAC1auv7prOWLVTwhWZeSY6tYh9n0KpUFXMR6pwSK2ABC5MiWqpjM0ojuyKDQLcNbMjIySwdbsK2ijnxnxMeQR8erzvSAEgYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724077800; c=relaxed/simple; bh=p50BBbuZosL/TlItQcko7jEGPGXXBIr8gIdvQs6tEdA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MmiLJVyLkh66A26cBmTmCZ9vzsPmJEvoGeCupShLy1i0pebgr0tfXqzY85jshSpLr04iw54ZyJ/G0CnzhBtvBhMbZtEx4LxOKyJ8P9sK4lmXFR3fhvxX/h9zHY110yfPpu9w/ymyf0H9QkbR+1/CnzitF5I77o38kjj4yOoNuVM= 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=bPpJDkbB; arc=none smtp.client-ip=192.198.163.10 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="bPpJDkbB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724077798; x=1755613798; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=p50BBbuZosL/TlItQcko7jEGPGXXBIr8gIdvQs6tEdA=; b=bPpJDkbBoUXTeAUAhlsGOfC4DoLfgAfKqWWMM9/byZo7F/g9NaouMOCs hZJpdxxiaCTZDN66IxgXkQ8czbJ++D2H3IFgNoCmP++D2x2gzL7R3S1EH 1HXmRnt6hQKG1X6oTh+U4v85MN20sx4v6XtU/bFr0kkmm+uNuOTr0u9rH zQcYdJwlH+OaMBNWMOQuuXvOjlC05kiVn5u4S/H5GE116kaGZfrvzD4f/ sBLC3Zsb22hGnMlQ5Mq5WnVeIcQVT+HhW+cmuEXhU1sI9HOfln6QUmuDF oHEf9gXlNe3Gw5gre7w7YULwRAQvEzkyv9gdVkqsC8nKTTKuc+yge3MO3 A==; X-CSE-ConnectionGUID: cGDtqvcnS6GCHtc0CqDaIQ== X-CSE-MsgGUID: s9ZEO/t/Sz+po0Yh7NETcA== X-IronPort-AV: E=McAfee;i="6700,10204,11169"; a="33744491" X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="33744491" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2024 07:29:55 -0700 X-CSE-ConnectionGUID: zsttDnP4SY63X7vIXkkq9Q== X-CSE-MsgGUID: NJOY/Nu2RTieT9MvbkiBBQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,159,1719903600"; d="scan'208";a="64783811" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa005.fm.intel.com with ESMTP; 19 Aug 2024 07:29:53 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 6E193719; Mon, 19 Aug 2024 17:29:49 +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 v2 5/5] gpiolib: Replace gpio_suffix_count with NULL-terminated array Date: Mon, 19 Aug 2024 17:29:00 +0300 Message-ID: <20240819142945.327808-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1336.g36b5255a03ac In-Reply-To: <20240819142945.327808-1-andriy.shevchenko@linux.intel.com> References: <20240819142945.327808-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 3a9668cc100d..3903d0a75304 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -90,8 +90,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 0271e747fb6e..067197d61d57 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