Skip to contentSkip to conversation

remove indentation for common path [linux-next]

PATCH Superseded sundar 3 participants 6 messages Apr 20, 2024 – Apr 21, 2024

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

sundar

author
#0 lore raw

PATCH v2 1/1 remove indentation for common path [linux-next]

Added check if pointer is null and removed indentation for common path

---

Fixed nitpicks in code according to comments received on other patch.

https://lore.kernel.org/all/2024041103-doornail-professor-7c1e@gregkh/

goal is to get rid of of_node_put,but sending this patch first to do one thing at a time.

Changes since v1 - fixed the typo error for spell from identation to indentation

v1 patch link - https://lore.kernel.org/all/[email protected]/

 drivers/usb/typec/mux/nb7vpq904m.c | 49 +++++++++++++++---------------
 1 file changed, 25 insertions(+), 24 deletions(-)
drivers/usb/typec/mux/nb7vpq904m.c +25 -24
index b17826713753..fe0257840dd5 100644
@@ -321,35 +321,37 @@ static int nb7vpq904m_parse_data_lanes_mapping(struct nb7vpq904m *nb7)
 
 	ep = of_graph_get_endpoint_by_regs(nb7->client->dev.of_node, 1, 0);
 
-	if (ep) {
-		ret = of_property_count_u32_elems(ep, "data-lanes");
-		if (ret == -EINVAL)
-			/* Property isn't here, consider default mapping */
-			goto out_done;
-		if (ret < 0)
-			goto out_error;
-
-		if (ret != DATA_LANES_COUNT) {
-			dev_err(&nb7->client->dev, "expected 4 data lanes\n");
-			ret = -EINVAL;
-			goto out_error;
-		}
+	if (!ep)
+		return 0;
 
-		ret = of_property_read_u32_array(ep, "data-lanes", data_lanes, DATA_LANES_COUNT);
-		if (ret)
-			goto out_error;
+	ret = of_property_count_u32_elems(ep, "data-lanes");
+	if (ret == -EINVAL)
+		/* Property isn't here, consider default mapping */
+		goto out_done;
+	if (ret < 0)
+		goto out_error;
+
+	if (ret != DATA_LANES_COUNT) {
+		dev_err(&nb7->client->dev, "expected 4 data lanes\n");
+		ret = -EINVAL;
+		goto out_error;
+	}
 
-		for (i = 0; i < ARRAY_SIZE(supported_data_lane_mapping); i++) {
-			for (j = 0; j < DATA_LANES_COUNT; j++) {
-				if (data_lanes[j] != supported_data_lane_mapping[i][j])
-					break;
-			}
+	ret = of_property_read_u32_array(ep, "data-lanes", data_lanes, DATA_LANES_COUNT);
+	if (ret)
+		goto out_error;
 
-			if (j == DATA_LANES_COUNT)
+	for (i = 0; i < ARRAY_SIZE(supported_data_lane_mapping); i++) {
+		for (j = 0; j < DATA_LANES_COUNT; j++) {
+			if (data_lanes[j] != supported_data_lane_mapping[i][j])
 				break;
 		}
 
-		switch (i) {
+		if (j == DATA_LANES_COUNT)
+			break;
+	}
+
+	switch (i) {
 		case NORMAL_LANE_MAPPING:
 			break;
 		case INVERT_LANE_MAPPING:
@@ -360,7 +362,6 @@ static int nb7vpq904m_parse_data_lanes_mapping(struct nb7vpq904m *nb7)
 			dev_err(&nb7->client->dev, "invalid data lanes mapping\n");
 			ret = -EINVAL;
 			goto out_error;
-		}
 	}
 
 out_done:
Signature · 1 line
2.34.1
#1 lore raw
Quoted 1 line · sundar

```

Added check if pointer is null and removed indentation for common path

```

[]

> ```
diff --git a/drivers/usb/typec/mux/nb7vpq904m.c b/drivers/usb/typec/mux/nb7vpq904m.c
```

[]

Quoted 1 line

```

@@ -321,35 +321,37 @@ static int nb7vpq904m_parse_data_lanes_mapping(struct nb7vpq904m *nb7)

ep = of_graph_get_endpoint_by_regs(nb7->client->dev.of_node, 1, 0);

- if (ep) {
- ret = of_property_count_u32_elems(ep, "data-lanes");
- if (ret == -EINVAL)
- /* Property isn't here, consider default mapping */
- goto out_done;
- if (ret < 0)
- goto out_error;
-
- if (ret != DATA_LANES_COUNT) {
- dev_err(&nb7->client->dev, "expected 4 data lanes\n");
- ret = -EINVAL;
- goto out_error;
- }
+ if (!ep)
+ return 0;
```

Not equivalent code as the out_error:

	of_node_put(ep);

isn't done

author
#2 lore raw
Quoted 26 lines · Joe Perches
Quoted 1 line · sundar

```

drivers/usb/typec/mux/nb7vpq904m.c +2 -13
@@ -321,35 +321,37 @@ static int nb7vpq904m_parse_data_lanes_mapping(struct nb7vpq904m *nb7)
 
  	ep = of_graph_get_endpoint_by_regs(nb7->client->dev.of_node, 1, 0);
 
-	if (ep) {
-		ret = of_property_count_u32_elems(ep, "data-lanes");
-		if (ret == -EINVAL)
-			/* Property isn't here, consider default mapping */
-			goto out_done;
-		if (ret < 0)
-			goto out_error;
-
-		if (ret != DATA_LANES_COUNT) {
-			dev_err(&nb7->client->dev, "expected 4 data lanes\n");
-			ret = -EINVAL;
-			goto out_error;
-		}
+	if (!ep)
+		return 0;

```

Quoted 7 lines

Not equivalent code as the out_error:

	of_node_put(ep);

isn't done

Hi joe perches,

If ep is null, I believe we dont need to call of_node_put. Because passing null pointer to of_node_put() make no difference.

In of_node_put() definition, if pointer is null, there is no operation.

Thanks,
Sundar

#3 lore raw
Quoted 37 lines · sundar
Quoted 26 lines · Joe Perches
Quoted 1 line · sundar

```

drivers/usb/typec/mux/nb7vpq904m.c +2 -13
@@ -321,35 +321,37 @@ static int nb7vpq904m_parse_data_lanes_mapping(struct nb7vpq904m *nb7)
 
  	ep = of_graph_get_endpoint_by_regs(nb7->client->dev.of_node, 1, 0);
 
-	if (ep) {
-		ret = of_property_count_u32_elems(ep, "data-lanes");
-		if (ret == -EINVAL)
-			/* Property isn't here, consider default mapping */
-			goto out_done;
-		if (ret < 0)
-			goto out_error;
-
-		if (ret != DATA_LANES_COUNT) {
-			dev_err(&nb7->client->dev, "expected 4 data lanes\n");
-			ret = -EINVAL;
-			goto out_error;
-		}
+	if (!ep)
+		return 0;

```

Quoted 7 lines

Not equivalent code as the out_error:

	of_node_put(ep);

isn't done

Hi joe perches,

Quoted 5 lines

If ep is null, I believe we dont need to call of_node_put. Because passing null pointer to of_node_put() make no difference.

In of_node_put() definition, if pointer is null, there is no operation.

Fine, but you should explain that in the changelog and not make reviewers look it up.

#4 lore raw
In reply to sundar
Quoted 75 lines · sundar

Added check if pointer is null and removed indentation for common path

---

Fixed nitpicks in code according to comments received on other patch.

https://lore.kernel.org/all/2024041103-doornail-professor-7c1e@gregkh/

goal is to get rid of of_node_put,but sending this patch first to do one thing at a time.

Changes since v1 - fixed the typo error for spell from identation to indentation

v1 patch link - https://lore.kernel.org/all/[email protected]/

 drivers/usb/typec/mux/nb7vpq904m.c | 49 +++++++++++++++---------------
 1 file changed, 25 insertions(+), 24 deletions(-)
drivers/usb/typec/mux/nb7vpq904m.c +20 -22
index b17826713753..fe0257840dd5 100644
@@ -321,35 +321,37 @@ static int nb7vpq904m_parse_data_lanes_mapping(struct nb7vpq904m *nb7)
 
        ep = of_graph_get_endpoint_by_regs(nb7->client->dev.of_node, 1, 0);
 
-       if (ep) {
-               ret = of_property_count_u32_elems(ep, "data-lanes");
-               if (ret == -EINVAL)
-                       /* Property isn't here, consider default mapping */
-                       goto out_done;
-               if (ret < 0)
-                       goto out_error;
-
-               if (ret != DATA_LANES_COUNT) {
-                       dev_err(&nb7->client->dev, "expected 4 data lanes\n");
-                       ret = -EINVAL;
-                       goto out_error;
-               }
+       if (!ep)
+               return 0;
 
-               ret = of_property_read_u32_array(ep, "data-lanes", data_lanes, DATA_LANES_COUNT);
-               if (ret)
-                       goto out_error;
+       ret = of_property_count_u32_elems(ep, "data-lanes");
+       if (ret == -EINVAL)
+               /* Property isn't here, consider default mapping */
+               goto out_done;
+       if (ret < 0)
+               goto out_error;
+
+       if (ret != DATA_LANES_COUNT) {
+               dev_err(&nb7->client->dev, "expected 4 data lanes\n");
+               ret = -EINVAL;
+               goto out_error;
+       }
 
-               for (i = 0; i < ARRAY_SIZE(supported_data_lane_mapping); i++) {
-                       for (j = 0; j < DATA_LANES_COUNT; j++) {
-                               if (data_lanes[j] != supported_data_lane_mapping[i][j])
-                                       break;
-                       }
+       ret = of_property_read_u32_array(ep, "data-lanes", data_lanes, DATA_LANES_COUNT);
+       if (ret)
+               goto out_error;
 
-                       if (j == DATA_LANES_COUNT)
+       for (i = 0; i < ARRAY_SIZE(supported_data_lane_mapping); i++) {
+               for (j = 0; j < DATA_LANES_COUNT; j++) {
+                       if (data_lanes[j] != supported_data_lane_mapping[i][j])

drivers/usb/typec/mux/nb7vpq904m.c static int nb7vpq904m_parse_data_lanes_mapping(struct nb7vpq904m *nb7) · line 355

Quoted 10 lines
drivers/usb/typec/mux/nb7vpq904m.c +5 -1
                                break;
                }
 
-               switch (i) {
+               if (j == DATA_LANES_COUNT)
+                       break;
+       }
+
+       switch (i) {
                case NORMAL_LANE_MAPPING:

switch-cases should also be shifted one level to the left, see Documentation/process/coding-style.rst

Quoted 13 lines
drivers/usb/typec/mux/nb7vpq904m.c +0 -2
                        break;
                case INVERT_LANE_MAPPING:
@@ -360,7 +362,6 @@ static int nb7vpq904m_parse_data_lanes_mapping(struct nb7vpq904m *nb7)
                        dev_err(&nb7->client->dev, "invalid data lanes mapping\n");
                        ret = -EINVAL;
                        goto out_error;
-               }
        }
 
 out_done:
--

2.34.1

Signature · 2 lines
With best wishes
Dmitry
author
#5 lore raw
Quoted 99 lines · Dmitry Baryshkov
Quoted 75 lines · sundar

Added check if pointer is null and removed indentation for common path

---

Fixed nitpicks in code according to comments received on other patch.

https://lore.kernel.org/all/2024041103-doornail-professor-7c1e@gregkh/

goal is to get rid of of_node_put,but sending this patch first to do one thing at a time.

Changes since v1 - fixed the typo error for spell from identation to indentation

v1 patch link - https://lore.kernel.org/all/[email protected]/

  drivers/usb/typec/mux/nb7vpq904m.c | 49 +++++++++++++++---------------
  1 file changed, 25 insertions(+), 24 deletions(-)
drivers/usb/typec/mux/nb7vpq904m.c +20 -22
index b17826713753..fe0257840dd5 100644
@@ -321,35 +321,37 @@ static int nb7vpq904m_parse_data_lanes_mapping(struct nb7vpq904m *nb7)
 
         ep = of_graph_get_endpoint_by_regs(nb7->client->dev.of_node, 1, 0);
 
-       if (ep) {
-               ret = of_property_count_u32_elems(ep, "data-lanes");
-               if (ret == -EINVAL)
-                       /* Property isn't here, consider default mapping */
-                       goto out_done;
-               if (ret < 0)
-                       goto out_error;
-
-               if (ret != DATA_LANES_COUNT) {
-                       dev_err(&nb7->client->dev, "expected 4 data lanes\n");
-                       ret = -EINVAL;
-                       goto out_error;
-               }
+       if (!ep)
+               return 0;
 
-               ret = of_property_read_u32_array(ep, "data-lanes", data_lanes, DATA_LANES_COUNT);
-               if (ret)
-                       goto out_error;
+       ret = of_property_count_u32_elems(ep, "data-lanes");
+       if (ret == -EINVAL)
+               /* Property isn't here, consider default mapping */
+               goto out_done;
+       if (ret < 0)
+               goto out_error;
+
+       if (ret != DATA_LANES_COUNT) {
+               dev_err(&nb7->client->dev, "expected 4 data lanes\n");
+               ret = -EINVAL;
+               goto out_error;
+       }
 
-               for (i = 0; i < ARRAY_SIZE(supported_data_lane_mapping); i++) {
-                       for (j = 0; j < DATA_LANES_COUNT; j++) {
-                               if (data_lanes[j] != supported_data_lane_mapping[i][j])
-                                       break;
-                       }
+       ret = of_property_read_u32_array(ep, "data-lanes", data_lanes, DATA_LANES_COUNT);
+       if (ret)
+               goto out_error;
 
-                       if (j == DATA_LANES_COUNT)
+       for (i = 0; i < ARRAY_SIZE(supported_data_lane_mapping); i++) {
+               for (j = 0; j < DATA_LANES_COUNT; j++) {
+                       if (data_lanes[j] != supported_data_lane_mapping[i][j])

drivers/usb/typec/mux/nb7vpq904m.c static int nb7vpq904m_parse_data_lanes_mapping(struct nb7vpq904m *nb7) · line 355

Quoted 10 lines
drivers/usb/typec/mux/nb7vpq904m.c +5 -1
                                 break;
                 }
 
-               switch (i) {
+               if (j == DATA_LANES_COUNT)
+                       break;
+       }
+
+       switch (i) {
                 case NORMAL_LANE_MAPPING:

switch-cases should also be shifted one level to the left, see Documentation/process/coding-style.rst

Quoted 9 lines
drivers/usb/typec/mux/nb7vpq904m.c +0 -1
                         break;
                 case INVERT_LANE_MAPPING:
@@ -360,7 +362,6 @@ static int nb7vpq904m_parse_data_lanes_mapping(struct nb7vpq904m *nb7)
                         dev_err(&nb7->client->dev, "invalid data lanes mapping\n");
                         ret = -EINVAL;
                         goto out_error;
-               }
         }
 
Quoted 6 lines
Quoted 4 lines
drivers/usb/typec/mux/nb7vpq904m.c +0 -1
  out_done:
--

2.34.1

Hi Dmitry,

Thanks for the review.will fix my code.

Thanks,
Sundar