* [PATCH v2] pinctrl: qcom: Fix logic error when TLMM reg-names property is missing
@ 2025-07-23 7:50 yuanjie yang
2025-07-23 11:27 ` Dmitry Baryshkov
0 siblings, 1 reply; 3+ messages in thread
From: yuanjie yang @ 2025-07-23 7:50 UTC (permalink / raw)
To: andersson, linus.walleij, linux-arm-msm, linux-gpio, linux-kernel
Cc: kernel, quic_tingweiz, quic_yuanjiey
From: Yuanjie Yang <yuanjie.yang@oss.qualcomm.com>
Some Qualcomm platforms, such as sm8750.dtsi, define a single TLMM
region without the reg-names property. This is a valid and expected
configuration. However, the current code incorrectly treats the absence
of reg-names as an error, resulting in unintended behavior.
Refactor the logic to handle both cases correctly:
If only the gpio parameter is provided, default to TLMM region 0.
If both gpio and name are provided, compare the reg-names entries in the
TLMM node with the given name to select the appropriate region.
Fixes: 56ffb63749f4 ("pinctrl: qcom: add multi TLMM region option parameter")
Signed-off-by: Yuanjie Yang <yuanjie.yang@oss.qualcomm.com>
---
- optimize commit message
- optimize code structure and fix kfree issue
- rebase on tag: next-20250723
- Link to v1: https://lore.kernel.org/all/20250722054446.3432-1-yuanjie.yang@oss.qualcomm.com/
---
drivers/pinctrl/qcom/tlmm-test.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/drivers/pinctrl/qcom/tlmm-test.c b/drivers/pinctrl/qcom/tlmm-test.c
index 7d7fff538755..e41fe7e76c80 100644
--- a/drivers/pinctrl/qcom/tlmm-test.c
+++ b/drivers/pinctrl/qcom/tlmm-test.c
@@ -581,10 +581,13 @@ static int tlmm_reg_base(struct device_node *tlmm, struct resource *res)
int ret;
int i;
+ if (!strcmp(tlmm_reg_name, "default_region"))
+ return of_address_to_resource(tlmm, 0, res);
+
count = of_property_count_strings(tlmm, "reg-names");
if (count <= 0) {
pr_err("failed to find tlmm reg name\n");
- return count;
+ return -EINVAL;
}
reg_names = kcalloc(count, sizeof(char *), GFP_KERNEL);
@@ -597,19 +600,16 @@ static int tlmm_reg_base(struct device_node *tlmm, struct resource *res)
return -EINVAL;
}
- if (!strcmp(tlmm_reg_name, "default_region")) {
- ret = of_address_to_resource(tlmm, 0, res);
- } else {
- for (i = 0; i < count; i++) {
- if (!strcmp(reg_names[i], tlmm_reg_name)) {
- ret = of_address_to_resource(tlmm, i, res);
- break;
- }
+ for (i = 0; i < count; i++) {
+ if (!strcmp(reg_names[i], tlmm_reg_name)) {
+ ret = of_address_to_resource(tlmm, i, res);
+ break;
}
- if (i == count)
- ret = -EINVAL;
}
+ if (i == count)
+ ret = -EINVAL;
+
kfree(reg_names);
return ret;
base-commit: a933d3dc1968fcfb0ab72879ec304b1971ed1b9a
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] pinctrl: qcom: Fix logic error when TLMM reg-names property is missing
2025-07-23 7:50 [PATCH v2] pinctrl: qcom: Fix logic error when TLMM reg-names property is missing yuanjie yang
@ 2025-07-23 11:27 ` Dmitry Baryshkov
2025-07-24 2:41 ` yuanjiey
0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Baryshkov @ 2025-07-23 11:27 UTC (permalink / raw)
To: yuanjie yang
Cc: andersson, linus.walleij, linux-arm-msm, linux-gpio, linux-kernel,
kernel, quic_tingweiz, quic_yuanjiey
On Wed, Jul 23, 2025 at 03:50:24PM +0800, yuanjie yang wrote:
> From: Yuanjie Yang <yuanjie.yang@oss.qualcomm.com>
>
> Some Qualcomm platforms, such as sm8750.dtsi, define a single TLMM
> region without the reg-names property. This is a valid and expected
> configuration. However, the current code incorrectly treats the absence
> of reg-names as an error, resulting in unintended behavior.
>
> Refactor the logic to handle both cases correctly:
> If only the gpio parameter is provided, default to TLMM region 0.
> If both gpio and name are provided, compare the reg-names entries in the
> TLMM node with the given name to select the appropriate region.
>
> Fixes: 56ffb63749f4 ("pinctrl: qcom: add multi TLMM region option parameter")
>
> Signed-off-by: Yuanjie Yang <yuanjie.yang@oss.qualcomm.com>
>
> ---
> - optimize commit message
> - optimize code structure and fix kfree issue
> - rebase on tag: next-20250723
> - Link to v1: https://lore.kernel.org/all/20250722054446.3432-1-yuanjie.yang@oss.qualcomm.com/
>
> ---
> drivers/pinctrl/qcom/tlmm-test.c | 22 +++++++++++-----------
> 1 file changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/pinctrl/qcom/tlmm-test.c b/drivers/pinctrl/qcom/tlmm-test.c
> index 7d7fff538755..e41fe7e76c80 100644
> --- a/drivers/pinctrl/qcom/tlmm-test.c
> +++ b/drivers/pinctrl/qcom/tlmm-test.c
> @@ -581,10 +581,13 @@ static int tlmm_reg_base(struct device_node *tlmm, struct resource *res)
> int ret;
> int i;
>
> + if (!strcmp(tlmm_reg_name, "default_region"))
> + return of_address_to_resource(tlmm, 0, res);
> +
> count = of_property_count_strings(tlmm, "reg-names");
> if (count <= 0) {
> pr_err("failed to find tlmm reg name\n");
> - return count;
> + return -EINVAL;
Why? It's better to propagate the error instead of reinventing it.
> }
>
> reg_names = kcalloc(count, sizeof(char *), GFP_KERNEL);
> @@ -597,19 +600,16 @@ static int tlmm_reg_base(struct device_node *tlmm, struct resource *res)
> return -EINVAL;
> }
>
> - if (!strcmp(tlmm_reg_name, "default_region")) {
> - ret = of_address_to_resource(tlmm, 0, res);
> - } else {
> - for (i = 0; i < count; i++) {
> - if (!strcmp(reg_names[i], tlmm_reg_name)) {
> - ret = of_address_to_resource(tlmm, i, res);
> - break;
> - }
> + for (i = 0; i < count; i++) {
> + if (!strcmp(reg_names[i], tlmm_reg_name)) {
> + ret = of_address_to_resource(tlmm, i, res);
> + break;
> }
> - if (i == count)
> - ret = -EINVAL;
> }
>
> + if (i == count)
> + ret = -EINVAL;
> +
> kfree(reg_names);
>
> return ret;
>
> base-commit: a933d3dc1968fcfb0ab72879ec304b1971ed1b9a
> --
> 2.34.1
>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] pinctrl: qcom: Fix logic error when TLMM reg-names property is missing
2025-07-23 11:27 ` Dmitry Baryshkov
@ 2025-07-24 2:41 ` yuanjiey
0 siblings, 0 replies; 3+ messages in thread
From: yuanjiey @ 2025-07-24 2:41 UTC (permalink / raw)
To: Dmitry Baryshkov
Cc: andersson, linus.walleij, linux-arm-msm, linux-gpio, linux-kernel,
kernel, quic_tingweiz, quic_yuanjiey
On Wed, Jul 23, 2025 at 02:27:46PM +0300, Dmitry Baryshkov wrote:
> On Wed, Jul 23, 2025 at 03:50:24PM +0800, yuanjie yang wrote:
> > From: Yuanjie Yang <yuanjie.yang@oss.qualcomm.com>
> >
> > Some Qualcomm platforms, such as sm8750.dtsi, define a single TLMM
> > region without the reg-names property. This is a valid and expected
> > configuration. However, the current code incorrectly treats the absence
> > of reg-names as an error, resulting in unintended behavior.
> >
> > Refactor the logic to handle both cases correctly:
> > If only the gpio parameter is provided, default to TLMM region 0.
> > If both gpio and name are provided, compare the reg-names entries in the
> > TLMM node with the given name to select the appropriate region.
> >
> > Fixes: 56ffb63749f4 ("pinctrl: qcom: add multi TLMM region option parameter")
> >
> > Signed-off-by: Yuanjie Yang <yuanjie.yang@oss.qualcomm.com>
> >
> > ---
> > - optimize commit message
> > - optimize code structure and fix kfree issue
> > - rebase on tag: next-20250723
> > - Link to v1: https://lore.kernel.org/all/20250722054446.3432-1-yuanjie.yang@oss.qualcomm.com/
> >
> > ---
> > drivers/pinctrl/qcom/tlmm-test.c | 22 +++++++++++-----------
> > 1 file changed, 11 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/pinctrl/qcom/tlmm-test.c b/drivers/pinctrl/qcom/tlmm-test.c
> > index 7d7fff538755..e41fe7e76c80 100644
> > --- a/drivers/pinctrl/qcom/tlmm-test.c
> > +++ b/drivers/pinctrl/qcom/tlmm-test.c
> > @@ -581,10 +581,13 @@ static int tlmm_reg_base(struct device_node *tlmm, struct resource *res)
> > int ret;
> > int i;
> >
> > + if (!strcmp(tlmm_reg_name, "default_region"))
> > + return of_address_to_resource(tlmm, 0, res);
> > +
> > count = of_property_count_strings(tlmm, "reg-names");
> > if (count <= 0) {
> > pr_err("failed to find tlmm reg name\n");
> > - return count;
> > + return -EINVAL;
>
> Why? It's better to propagate the error instead of reinventing it.
of_property_count_strings often return value > 0 (count) or value < 0 (error code).
But theoretically the return value can equal 0 (value == 0), perhaps this situation
will not happen.
However, from the code logic perspective, this tool should early return when count<=0,
if return count == 0, code flow can not stop, this will lead to a mistake in the tool.
line:
639:ret = tlmm_reg_base(tlmm, &res);
640:if (ret < 0)
641: return ret;
With this consideration, I have reinvented the error code.
> > }
> >
> > reg_names = kcalloc(count, sizeof(char *), GFP_KERNEL);
> > @@ -597,19 +600,16 @@ static int tlmm_reg_base(struct device_node *tlmm, struct resource *res)
> > return -EINVAL;
> > }
> >
> > - if (!strcmp(tlmm_reg_name, "default_region")) {
> > - ret = of_address_to_resource(tlmm, 0, res);
> > - } else {
> > - for (i = 0; i < count; i++) {
> > - if (!strcmp(reg_names[i], tlmm_reg_name)) {
> > - ret = of_address_to_resource(tlmm, i, res);
> > - break;
> > - }
> > + for (i = 0; i < count; i++) {
> > + if (!strcmp(reg_names[i], tlmm_reg_name)) {
> > + ret = of_address_to_resource(tlmm, i, res);
> > + break;
> > }
> > - if (i == count)
> > - ret = -EINVAL;
> > }
> >
> > + if (i == count)
> > + ret = -EINVAL;
> > +
> > kfree(reg_names);
> >
> > return ret;
> >
> > base-commit: a933d3dc1968fcfb0ab72879ec304b1971ed1b9a
> > --
> > 2.34.1
> >
>
> --
> With best wishes
> Dmitry
Thanks,
Yuanjie
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-24 2:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-23 7:50 [PATCH v2] pinctrl: qcom: Fix logic error when TLMM reg-names property is missing yuanjie yang
2025-07-23 11:27 ` Dmitry Baryshkov
2025-07-24 2:41 ` yuanjiey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).