Skip to contentSkip to conversation

staging: most: Fix coding style problems.

PATCH In review Quytelda Kahja 4 participants 15 messages Feb 24, 2018 – Mar 7, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 staging: most: Fix coding style problems.

Makes two very minor changes indicated by checkpatch:
1) Add a newline after components_show() definition.
2) Fix a line over the 80 character limit.

---
 drivers/staging/most/core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/staging/most/core.c +4 -1
index 3dda8d81bf0b..18157dd80324 100644
@@ -583,6 +583,7 @@ static ssize_t components_show(struct device_driver *drv, char *buf)
 	}
 	return offs;
 }
+
 /**
  * split_string - parses buf and extracts ':' separated substrings.
  *
@@ -1474,7 +1475,9 @@ void most_deregister_interface(struct most_interface *iface)
 	int i;
 	struct most_channel *c;
 
-	pr_info("deregistering device %s (%s)\n", dev_name(&iface->dev), iface->description);
+	pr_info("deregistering device %s (%s)\n",
+		dev_name(&iface->dev),
+		iface->description);
 	for (i = 0; i < iface->num_channels; i++) {
 		c = iface->p->channel[i];
 		if (c->pipe0.comp)
Signature · 6 lines
2.16.2

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
#1 lore raw

PATCH 2/4 staging: most: Replace calls to BUG_ON() with WARN_ONCE() and return.

Replace calls to BUG_ON() used to check for NULL pointers with WARN_ONCE() followed by a return.

---
 drivers/staging/most/core.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/staging/most/core.c +10 -3
index 18157dd80324..3f65390a6e17 100644
@@ -916,7 +916,11 @@ static void arm_mbo(struct mbo *mbo)
 	unsigned long flags;
 	struct most_channel *c;
 
-	BUG_ON((!mbo) || (!mbo->context));
+	if (WARN_ONCE(!mbo || !mbo->context,
+		      "Bad mbo or missing channel reference.\n")) {
+		return;
+	}
+
 	c = mbo->context;
 
 	if (c->is_poisoned) {
@@ -1001,7 +1005,7 @@ static int arm_mbo_chain(struct most_channel *c, int dir,
 void most_submit_mbo(struct mbo *mbo)
 {
 	if (WARN_ONCE(!mbo || !mbo->context,
-		      "bad mbo or missing channel reference\n"))
+		      "Bad mbo or missing channel reference.\n"))
 		return;
 
 	nq_hdm_mbo(mbo);
@@ -1019,7 +1023,10 @@ static void most_write_completion(struct mbo *mbo)
 {
 	struct most_channel *c;
 
-	BUG_ON((!mbo) || (!mbo->context));
+	if (WARN_ONCE(!mbo || !mbo->context,
+		      "Bad mbo or missing channel reference.\n")) {
+		return;
+	}
 
 	c = mbo->context;
 	if (mbo->status == MBO_E_INVAL)
Signature · 6 lines
2.16.2

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
maintainer
#2 lore raw

Re: [PATCH 2/4] staging: most: Replace calls to BUG_ON() with WARN_ONCE() and return.

Quoted 2 lines · Quytelda Kahja

Replace calls to BUG_ON() used to check for NULL pointers with WARN_ONCE() followed by a return.

Are you sure this will work?

Quoted 11 lines
---
 drivers/staging/most/core.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/staging/most/core.c +0 -0
index 18157dd80324..3f65390a6e17 100644

drivers/staging/most/core.c static void arm_mbo(struct mbo *mbo) · line 921

Quoted 7 lines
drivers/staging/most/core.c +3 -1
@@ -916,7 +916,11 @@ static void arm_mbo(struct mbo *mbo)
 	unsigned long flags;
 	struct most_channel *c;
 
-	BUG_ON((!mbo) || (!mbo->context));
+	if (WARN_ONCE(!mbo || !mbo->context,
+		      "Bad mbo or missing channel reference.\n")) {
+		return;

How is the code supposed to recover from this major problem?

drivers/staging/most/core.c static int arm_mbo_chain(struct most_channel *c, int dir, · line 1008

Quoted 11 lines
drivers/staging/most/core.c +3 -1
+	}
+
 	c = mbo->context;
 
 	if (c->is_poisoned) {
@@ -1001,7 +1005,7 @@ static int arm_mbo_chain(struct most_channel *c, int dir,
 void most_submit_mbo(struct mbo *mbo)
 {
 	if (WARN_ONCE(!mbo || !mbo->context,
-		      "bad mbo or missing channel reference\n"))
+		      "Bad mbo or missing channel reference.\n"))

You did something different here that you did not describe in your changelog :(

thanks,

greg k-h
_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

#3 lore raw

Re: [PATCH 2/4] staging: most: Replace calls to BUG_ON() with WARN_ONCE() and return.

Quoted 1 line

Are you sure this will work?

Well, my goal was just to replace the code that could crash the kernel and let somebody with a better understanding of this particular driver write the recovery code, if necessary. It seemed from context that the BUG_ON() calls were being used like assert() though, so I assumed there wasn't really much recovery to be made from that problem. If you feel this doesn't improve the behavior of the driver, just drop the patch.

Thank you,
Quytelda Kahja

Quoted 42 lines · Greg KH
Quoted 2 lines · Quytelda Kahja

Replace calls to BUG_ON() used to check for NULL pointers with WARN_ONCE() followed by a return.

Are you sure this will work?

Quoted 11 lines
---
 drivers/staging/most/core.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/staging/most/core.c +0 -0
index 18157dd80324..3f65390a6e17 100644

drivers/staging/most/core.c static void arm_mbo(struct mbo *mbo) · line 921

Quoted 7 lines
drivers/staging/most/core.c +3 -1
@@ -916,7 +916,11 @@ static void arm_mbo(struct mbo *mbo)
      unsigned long flags;
      struct most_channel *c;
 
-     BUG_ON((!mbo) || (!mbo->context));
+     if (WARN_ONCE(!mbo || !mbo->context,
+                   "Bad mbo or missing channel reference.\n")) {
+             return;

How is the code supposed to recover from this major problem?

drivers/staging/most/core.c static int arm_mbo_chain(struct most_channel *c, int dir, · line 1008

Quoted 11 lines
drivers/staging/most/core.c +3 -1
+     }
+
      c = mbo->context;
 
      if (c->is_poisoned) {
@@ -1001,7 +1005,7 @@ static int arm_mbo_chain(struct most_channel *c, int dir,
 void most_submit_mbo(struct mbo *mbo)
 {
      if (WARN_ONCE(!mbo || !mbo->context,
-                   "bad mbo or missing channel reference\n"))
+                   "Bad mbo or missing channel reference.\n"))

You did something different here that you did not describe in your changelog :(

Quoted 3 lines

thanks,

greg k-h

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

#4 lore raw

Re: [PATCH 2/4] staging: most: Replace calls to BUG_ON() with WARN_ONCE() and return.

Quoted 9 lines · Quytelda Kahja
Quoted 1 line

Are you sure this will work?

Well, my goal was just to replace the code that could crash the kernel and let somebody with a better understanding of this particular driver write the recovery code, if necessary. It seemed from context that the BUG_ON() calls were being used like assert() though, so I assumed there wasn't really much recovery to be made from that problem. If you feel this doesn't improve the behavior of the driver, just drop the patch.

mbo is always non-NULL just from a quick glance. I didn't look hard enough to verify that mbo->context was OK.

It's generally best to just check the callers and delete these.

Say you have a BUG_ON() then that prevents memory corruption (not an issue here) but it makes debugging hard. But if you just have a NULL dereference it probably kills the driver but you get an Oops which you can debug. So a NULL dereference is normally better than a BUG_ON().

regards,
dan carpenter

#5 lore raw

PATCH 1/1 staging: most: Remove unnecessary usage of BUG_ON().

There is no need for the calls to BUG_ON() in this driver, which are used to check if mbo or mbo->context are NULL; mbo is never NULL, and if mbo->context is NULL it would have already been dereferenced and oopsed before reaching the BUG_ON().

---
 drivers/staging/most/core.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/staging/most/core.c +0 -3
index 0ab2de5ecf18..3afc25a61643 100644
@@ -915,7 +915,6 @@ static void arm_mbo(struct mbo *mbo)
 	unsigned long flags;
 	struct most_channel *c;
 
-	BUG_ON((!mbo) || (!mbo->context));
 	c = mbo->context;
 
 	if (c->is_poisoned) {
@@ -1018,8 +1017,6 @@ static void most_write_completion(struct mbo *mbo)
 {
 	struct most_channel *c;
 
-	BUG_ON((!mbo) || (!mbo->context));
-
 	c = mbo->context;
 	if (mbo->status == MBO_E_INVAL)
 		pr_info("WARN: Tx MBO status: invalid\n");
Signature · 6 lines
2.16.2

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
maintainer Acked-by on v1 1/1
#6 lore raw

Re: [PATCH] staging: most: Remove unnecessary usage of BUG_ON().

Quoted 6 lines · Quytelda Kahja

There is no need for the calls to BUG_ON() in this driver, which are used to check if mbo or mbo->context are NULL; mbo is never NULL, and if mbo->context is NULL it would have already been dereferenced and oopsed before reaching the BUG_ON().

Quoted 18 lines
---
  drivers/staging/most/core.c | 3 ---
  1 file changed, 3 deletions(-)
drivers/staging/most/core.c +0 -1
index 0ab2de5ecf18..3afc25a61643 100644
@@ -915,7 +915,6 @@ static void arm_mbo(struct mbo *mbo)
  	unsigned long flags;
  	struct most_channel *c;
 
-	BUG_ON((!mbo) || (!mbo->context));
  	c = mbo->context;
 
  	if (c->is_poisoned) {

drivers/staging/most/core.c static void most_write_completion(struct mbo *mbo) · line 1022

Quoted 8 lines
drivers/staging/most/core.c +0 -2
@@ -1018,8 +1017,6 @@ static void most_write_completion(struct mbo *mbo)
  {
  	struct most_channel *c;
 
-	BUG_ON((!mbo) || (!mbo->context));
-
  	c = mbo->context;
  	if (mbo->status == MBO_E_INVAL)
  		pr_info("WARN: Tx MBO status: invalid\n");

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

#7 lore raw

PATCH 3/4 staging: most: Remove unnecessary OOM messages.

In reply to Quytelda Kahja

It isn't necessary for the driver to log out-of-memory errors, so these have been removed and the functions simply return -ENOMEM.

---
 drivers/staging/most/core.c | 2 --
 1 file changed, 2 deletions(-)
drivers/staging/most/core.c +0 -2
index 3f65390a6e17..b8792d70db8b 100644
@@ -1210,7 +1210,6 @@ int most_start_channel(struct most_interface *iface, int id,
 		num_buffer = arm_mbo_chain(c, c->cfg.direction,
 					   most_write_completion);
 	if (unlikely(!num_buffer)) {
-		pr_info("failed to allocate memory\n");
 		ret = -ENOMEM;
 		goto error;
 	}
@@ -1389,7 +1388,6 @@ int most_register_interface(struct most_interface *iface)
 
 	iface->p = kzalloc(sizeof(*iface->p), GFP_KERNEL);
 	if (!iface->p) {
-		pr_info("Failed to allocate interface instance\n");
 		ida_simple_remove(&mdev_id, id);
 		return -ENOMEM;
 	}
Signature · 6 lines
2.16.2

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
#8 lore raw

PATCH 4/4 staging: most: Fix missing identifier in function definition argument.

In reply to Quytelda Kahja

The function pointer 'complete' in 'struct mbo' should use an identifier for its argument.

---
 drivers/staging/most/core.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/most/core.h +1 -1
index 74a29163b68a..884bd71fafce 100644
@@ -184,7 +184,7 @@ struct mbo {
 	u16 buffer_length;
 	u16 processed_length;
 	enum mbo_status_flags status;
-	void (*complete)(struct mbo *);
+	void (*complete)(struct mbo *mbo);
 };
 
 /**
Signature · 6 lines
2.16.2

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
maintainer
#9 lore raw
In reply to Quytelda Kahja
Quoted 3 lines · Quytelda Kahja

Makes two very minor changes indicated by checkpatch:
1) Add a newline after components_show() definition.
2) Fix a line over the 80 character limit.

Do not do multiple things in the same patch, whenever possible. Please break this up into 2 patches.

thanks,

greg k-h
_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

#10 lore raw

PATCH 1/2 staging: most: Fix a coding style problem.

Use a blank line after components_show() function declaration.

---
 drivers/staging/most/core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/staging/most/core.c +1 -0
index 0ab2de5ecf18..67e2d7f29967 100644
@@ -583,6 +583,7 @@ static ssize_t components_show(struct device_driver *drv, char *buf)
 	}
 	return offs;
 }
+
 /**
  * split_string - parses buf and extracts ':' separated substrings.
  *
Signature · 6 lines
2.16.2

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
#11 lore raw

PATCH 2/2 staging: most: Fix a coding style problem

Indent the parameters for a function call that extends past 80 characters.

---
 drivers/staging/most/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/most/core.c +2 -1
index 67e2d7f29967..8d311970225e 100644
@@ -1473,7 +1473,8 @@ void most_deregister_interface(struct most_interface *iface)
 	int i;
 	struct most_channel *c;
 
-	pr_info("deregistering device %s (%s)\n", dev_name(&iface->dev), iface->description);
+	pr_info("deregistering device %s (%s)\n", dev_name(&iface->dev),
+		iface->description);
 	for (i = 0; i < iface->num_channels; i++) {
 		c = iface->p->channel[i];
 		if (c->pipe0.comp)
Signature · 6 lines
2.16.2

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
#13 lore raw

PATCH v2 1/2 staging: most: Add a blank line.

Use a blank line after components_show() function declaration.

---
 drivers/staging/most/core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/staging/most/core.c +1 -0
index 0ab2de5ecf18..67e2d7f29967 100644
@@ -583,6 +583,7 @@ static ssize_t components_show(struct device_driver *drv, char *buf)
 	}
 	return offs;
 }
+
 /**
  * split_string - parses buf and extracts ':' separated substrings.
  *
Signature · 6 lines
2.16.2

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
#14 lore raw

PATCH v2 2/2 staging: most: Indent function parameter.

In reply to Dan Carpenter

Indent the parameters for a function call that extends past 80 characters.

---
 drivers/staging/most/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/most/core.c +2 -1
index 67e2d7f29967..8d311970225e 100644
@@ -1473,7 +1473,8 @@ void most_deregister_interface(struct most_interface *iface)
 	int i;
 	struct most_channel *c;
 
-	pr_info("deregistering device %s (%s)\n", dev_name(&iface->dev), iface->description);
+	pr_info("deregistering device %s (%s)\n", dev_name(&iface->dev),
+		iface->description);
 	for (i = 0; i < iface->num_channels; i++) {
 		c = iface->p->channel[i];
 		if (c->pipe0.comp)
Signature · 6 lines
2.16.2

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel