Skip to contentSkip to conversation

bus: bt1-apb: Include linux/io.h

PATCH New Serge Semin 1 participant 6 messages May 28, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 bus: bt1-apb: Include linux/io.h

It must be included since we are using readl() method here.

Cc Alexey Malahov <[email protected]>
Cc Olof Johansson <[email protected]>
Cc Andy Shevchenko <[email protected]>
---
 drivers/bus/bt1-apb.c | 1 +
 1 file changed, 1 insertion(+)
drivers/bus/bt1-apb.c +1 -0
index abccd1dfc544..839f1add2236 100644
@@ -15,6 +15,7 @@
 #include <linux/atomic.h>
 #include <linux/platform_device.h>
 #include <linux/interrupt.h>
+#include <linux/io.h>
 #include <linux/nmi.h>
 #include <linux/of.h>
 #include <linux/regmap.h>
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/6 bus: bt1-apb: Fix show/store callback identations

After fixing the sysfs calback return value the functions argumnets identations have been left as before the fix. That made the argments declarations being unaligned with respect to the space surrounded by the parentheses.

Cc Alexey Malahov <[email protected]>
Cc Olof Johansson <[email protected]>
Cc Andy Shevchenko <[email protected]>
---
 drivers/bus/bt1-apb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/bus/bt1-apb.c +4 -4
index 839f1add2236..59ec5e7077e8 100644
@@ -311,15 +311,15 @@ static ssize_t timeout_store(struct device *dev,
 }
 static DEVICE_ATTR_RW(timeout);
 
-static ssize_t inject_error_show(struct device *dev, struct device_attribute *attr,
-			     char *buf)
+static ssize_t inject_error_show(struct device *dev,
+				 struct device_attribute *attr, char *buf)
 {
 	return scnprintf(buf, PAGE_SIZE, "Error injection: nodev irq\n");
 }
 
 static ssize_t inject_error_store(struct device *dev,
-			      struct device_attribute *attr,
-			      const char *data, size_t count)
+				  struct device_attribute *attr,
+				  const char *data, size_t count)
 {
 	struct bt1_apb *apb = dev_get_drvdata(dev);
 
Signature · 1 line
2.26.2
#2 lore raw

PATCH 3/6 bus: bt1-apb: Use PTR_ERR_OR_ZERO to return from request-regs method

In reply to Serge Semin

Indeed it's more optimal to use the PTR_ERR_OR_ZERO() macro there instead of having two return points.

Cc Alexey Malahov <[email protected]>
Cc Olof Johansson <[email protected]>
Cc Andy Shevchenko <[email protected]>
---
 drivers/bus/bt1-apb.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/bus/bt1-apb.c +2 -4
index 59ec5e7077e8..7e57fc2af745 100644
@@ -164,12 +164,10 @@ static int bt1_apb_request_regs(struct bt1_apb *apb)
 	}
 
 	apb->res = devm_platform_ioremap_resource_byname(pdev, "nodev");
-	if (IS_ERR(apb->res)) {
+	if (IS_ERR(apb->res))
 		dev_err(apb->dev, "Couldn't map reserved region\n");
-		return PTR_ERR(apb->res);
-	}
 
-	return 0;
+	return PTR_ERR_OR_ZERO(apb->res);
 }
 
 static int bt1_apb_request_rst(struct bt1_apb *apb)
Signature · 1 line
2.26.2
#3 lore raw

PATCH 4/6 bus: bt1-apb: Use sysfs_streq instead of strncmp

In reply to Serge Semin

There is a ready-to-use method to compare a retrieved from a sysfs node string with another string. It treats both NUL and newline-then-NUL as equivalent string terminations. So use it instead of manually truncating the line length in the strncmp() method.

Cc Alexey Malahov <[email protected]>
Cc Olof Johansson <[email protected]>
Cc Andy Shevchenko <[email protected]>
---
 drivers/bus/bt1-apb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/bus/bt1-apb.c +2 -2
index 7e57fc2af745..b25ff941e7c7 100644
@@ -325,9 +325,9 @@ static ssize_t inject_error_store(struct device *dev,
 	 * Either dummy read from the unmapped address in the APB IO area
 	 * or manually set the IRQ status.
 	 */
-	if (!strncmp(data, "nodev", 5))
+	if (sysfs_streq(data, "nodev"))
 		readl(apb->res);
-	else if (!strncmp(data, "irq", 3))
+	else if (sysfs_streq(data, "irq"))
 		regmap_update_bits(apb->regs, APB_EHB_ISR, APB_EHB_ISR_PENDING,
 				   APB_EHB_ISR_PENDING);
 	else
Signature · 1 line
2.26.2
#4 lore raw

PATCH 5/6 bus: bt1-axi: Optimize the return points in the driver

In reply to Serge Semin

It's better to have a single return statement where it's applicable instead of returning from a conditional statement if-clause. Let's do this in the request registers, clock and IRQ methods.

Cc Alexey Malahov <[email protected]>
Cc Olof Johansson <[email protected]>
Cc Andy Shevchenko <[email protected]>
---
 drivers/bus/bt1-axi.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/bus/bt1-axi.c +6 -12
index 2005f9174118..c194d9a2bbeb 100644
@@ -124,12 +124,10 @@ static int bt1_axi_request_regs(struct bt1_axi *axi)
 	}
 
 	axi->qos_regs = devm_platform_ioremap_resource_byname(pdev, "qos");
-	if (IS_ERR(axi->qos_regs)) {
+	if (IS_ERR(axi->qos_regs))
 		dev_err(dev, "Couldn't map AXI-bus QoS registers\n");
-		return PTR_ERR(axi->qos_regs);
-	}
 
-	return 0;
+	return PTR_ERR_OR_ZERO(axi->qos_regs);
 }
 
 static int bt1_axi_request_rst(struct bt1_axi *axi)
@@ -173,12 +171,10 @@ static int bt1_axi_request_clk(struct bt1_axi *axi)
 	}
 
 	ret = devm_add_action_or_reset(axi->dev, bt1_axi_disable_clk, axi);
-	if (ret) {
+	if (ret)
 		dev_err(axi->dev, "Can't add AXI clock disable action\n");
-		return ret;
-	}
 
-	return 0;
+	return ret;
 }
 
 static int bt1_axi_request_irq(struct bt1_axi *axi)
@@ -192,12 +188,10 @@ static int bt1_axi_request_irq(struct bt1_axi *axi)
 
 	ret = devm_request_irq(axi->dev, axi->irq, bt1_axi_isr, IRQF_SHARED,
 			       "bt1-axi", axi);
-	if (ret) {
+	if (ret)
 		dev_err(axi->dev, "Couldn't request AXI EHB IRQ\n");
-		return ret;
-	}
 
-	return 0;
+	return ret;
 }
 
 static ssize_t count_show(struct device *dev,
Signature · 1 line
2.26.2
#5 lore raw

PATCH 6/6 bus: bt1-axi: Use sysfs_streq instead of strncmp

In reply to Serge Semin

There is a ready-to-use method to compare a retrieved from a sysfs node string with another string. It treats both NUL and newline-then-NUL as equivalent string terminations. So use it instead of manually truncating the line length in the strncmp() method.

Cc Alexey Malahov <[email protected]>
Cc Olof Johansson <[email protected]>
Cc Andy Shevchenko <[email protected]>
---
 drivers/bus/bt1-axi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/bus/bt1-axi.c +2 -2
index c194d9a2bbeb..e7a6744acc7b 100644
@@ -220,9 +220,9 @@ static ssize_t inject_error_store(struct device *dev,
 	 * error while unaligned writing - the AXI bus write error handled
 	 * by this driver.
 	 */
-	if (!strncmp(data, "bus", 3))
+	if (sysfs_streq(data, "bus"))
 		readb(axi->qos_regs);
-	else if (!strncmp(data, "unaligned", 9))
+	else if (sysfs_streq(data, "unaligned"))
 		writeb(0, axi->qos_regs);
 	else
 		return -EINVAL;
Signature · 1 line
2.26.2