drivers/pinctrl/qcom/tlmm-test.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
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.
Refactoring 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.
This ensures proper handling of platforms with either single or multiple
TLMM regions.
Fixes: 56ffb63749f4 ("pinctrl: qcom: add multi TLMM region option parameter")
Signed-off-by: Yuanjie Yang <yuanjie.yang@oss.qualcomm.com>
---
drivers/pinctrl/qcom/tlmm-test.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/drivers/pinctrl/qcom/tlmm-test.c b/drivers/pinctrl/qcom/tlmm-test.c
index 7d7fff538755..6de8cf23f9f0 100644
--- a/drivers/pinctrl/qcom/tlmm-test.c
+++ b/drivers/pinctrl/qcom/tlmm-test.c
@@ -581,25 +581,25 @@ static int tlmm_reg_base(struct device_node *tlmm, struct resource *res)
int ret;
int i;
- count = of_property_count_strings(tlmm, "reg-names");
- if (count <= 0) {
- pr_err("failed to find tlmm reg name\n");
- return count;
- }
-
- reg_names = kcalloc(count, sizeof(char *), GFP_KERNEL);
- if (!reg_names)
- return -ENOMEM;
-
- ret = of_property_read_string_array(tlmm, "reg-names", reg_names, count);
- if (ret != count) {
- kfree(reg_names);
- return -EINVAL;
- }
-
if (!strcmp(tlmm_reg_name, "default_region")) {
ret = of_address_to_resource(tlmm, 0, res);
} else {
+ count = of_property_count_strings(tlmm, "reg-names");
+ if (count <= 0) {
+ pr_err("failed to find tlmm reg name\n");
+ return -EINVAL;
+ }
+
+ reg_names = kcalloc(count, sizeof(char *), GFP_KERNEL);
+ if (!reg_names)
+ return -ENOMEM;
+
+ ret = of_property_read_string_array(tlmm, "reg-names", reg_names, count);
+ if (ret != count) {
+ kfree(reg_names);
+ return -EINVAL;
+ }
+
for (i = 0; i < count; i++) {
if (!strcmp(reg_names[i], tlmm_reg_name)) {
ret = of_address_to_resource(tlmm, i, res);
base-commit: d086c886ceb9f59dea6c3a9dae7eb89e780a20c9
--
2.34.1
On Tue, Jul 22, 2025 at 01:44:46PM +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. > > Refactoring the logic to handle both cases correctly: s/Refactoring/Refactor/g > 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. > > This ensures proper handling of platforms with either single or multiple > TLMM regions. Drop this sentence. > > Fixes: 56ffb63749f4 ("pinctrl: qcom: add multi TLMM region option parameter") > > Signed-off-by: Yuanjie Yang <yuanjie.yang@oss.qualcomm.com> No empty lines between the tags. > --- > drivers/pinctrl/qcom/tlmm-test.c | 32 ++++++++++++++++---------------- > 1 file changed, 16 insertions(+), 16 deletions(-) > > diff --git a/drivers/pinctrl/qcom/tlmm-test.c b/drivers/pinctrl/qcom/tlmm-test.c > index 7d7fff538755..6de8cf23f9f0 100644 > --- a/drivers/pinctrl/qcom/tlmm-test.c > +++ b/drivers/pinctrl/qcom/tlmm-test.c > @@ -581,25 +581,25 @@ static int tlmm_reg_base(struct device_node *tlmm, struct resource *res) > int ret; > int i; > > - count = of_property_count_strings(tlmm, "reg-names"); > - if (count <= 0) { > - pr_err("failed to find tlmm reg name\n"); > - return count; > - } > - > - reg_names = kcalloc(count, sizeof(char *), GFP_KERNEL); > - if (!reg_names) > - return -ENOMEM; > - > - ret = of_property_read_string_array(tlmm, "reg-names", reg_names, count); > - if (ret != count) { > - kfree(reg_names); > - return -EINVAL; > - } > - > if (!strcmp(tlmm_reg_name, "default_region")) { > ret = of_address_to_resource(tlmm, 0, res); return here and remove braces around the else clause. It's strange that you didn't get the warning about calling kfree on the uninitialized variable. > } else { > + count = of_property_count_strings(tlmm, "reg-names"); > + if (count <= 0) { > + pr_err("failed to find tlmm reg name\n"); > + return -EINVAL; > + } > + > + reg_names = kcalloc(count, sizeof(char *), GFP_KERNEL); > + if (!reg_names) > + return -ENOMEM; > + > + ret = of_property_read_string_array(tlmm, "reg-names", reg_names, count); > + if (ret != count) { > + kfree(reg_names); > + return -EINVAL; > + } > + > for (i = 0; i < count; i++) { > if (!strcmp(reg_names[i], tlmm_reg_name)) { > ret = of_address_to_resource(tlmm, i, res); > > base-commit: d086c886ceb9f59dea6c3a9dae7eb89e780a20c9 > -- > 2.34.1 > -- With best wishes Dmitry
On Tue, Jul 22, 2025 at 09:38:51AM +0300, Dmitry Baryshkov wrote: > On Tue, Jul 22, 2025 at 01:44:46PM +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. > > > > Refactoring the logic to handle both cases correctly: > > s/Refactoring/Refactor/g will update. > > 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. > > > > This ensures proper handling of platforms with either single or multiple > > TLMM regions. > > Drop this sentence. will update. > > > > Fixes: 56ffb63749f4 ("pinctrl: qcom: add multi TLMM region option parameter") > > > > Signed-off-by: Yuanjie Yang <yuanjie.yang@oss.qualcomm.com> > > No empty lines between the tags. will update. > > --- > > drivers/pinctrl/qcom/tlmm-test.c | 32 ++++++++++++++++---------------- > > 1 file changed, 16 insertions(+), 16 deletions(-) > > > > diff --git a/drivers/pinctrl/qcom/tlmm-test.c b/drivers/pinctrl/qcom/tlmm-test.c > > index 7d7fff538755..6de8cf23f9f0 100644 > > --- a/drivers/pinctrl/qcom/tlmm-test.c > > +++ b/drivers/pinctrl/qcom/tlmm-test.c > > @@ -581,25 +581,25 @@ static int tlmm_reg_base(struct device_node *tlmm, struct resource *res) > > int ret; > > int i; > > > > - count = of_property_count_strings(tlmm, "reg-names"); > > - if (count <= 0) { > > - pr_err("failed to find tlmm reg name\n"); > > - return count; > > - } > > - > > - reg_names = kcalloc(count, sizeof(char *), GFP_KERNEL); > > - if (!reg_names) > > - return -ENOMEM; > > - > > - ret = of_property_read_string_array(tlmm, "reg-names", reg_names, count); > > - if (ret != count) { > > - kfree(reg_names); > > - return -EINVAL; > > - } > > - > > if (!strcmp(tlmm_reg_name, "default_region")) { > > ret = of_address_to_resource(tlmm, 0, res); > > return here and remove braces around the else clause. It's strange that > you didn't get the warning about calling kfree on the uninitialized > variable. Thanks, will remove braces and fix kfree issue. > > } else { > > + count = of_property_count_strings(tlmm, "reg-names"); > > + if (count <= 0) { > > + pr_err("failed to find tlmm reg name\n"); > > + return -EINVAL; > > + } > > + > > + reg_names = kcalloc(count, sizeof(char *), GFP_KERNEL); > > + if (!reg_names) > > + return -ENOMEM; > > + > > + ret = of_property_read_string_array(tlmm, "reg-names", reg_names, count); > > + if (ret != count) { > > + kfree(reg_names); > > + return -EINVAL; > > + } > > + > > for (i = 0; i < count; i++) { > > if (!strcmp(reg_names[i], tlmm_reg_name)) { > > ret = of_address_to_resource(tlmm, i, res); > > > > base-commit: d086c886ceb9f59dea6c3a9dae7eb89e780a20c9 > > -- > > 2.34.1 > > > > -- > With best wishes > Dmitry Thanks, Yuanjie
© 2016 - 2025 Red Hat, Inc.