All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xenbus: Neaten xenbus_va_dev_error
@ 2017-02-08 11:33 ` Joe Perches
  0 siblings, 0 replies; 10+ messages in thread
From: Joe Perches @ 2017-02-08 11:33 UTC (permalink / raw)
  To: linux-kernel; +Cc: Boris Ostrovsky, Juergen Gross, xen-devel

This function error patch can be simplified, so do so.

Remove fail: label and somewhat obfuscating, used once "error_path"
function.

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/xen/xenbus/xenbus_client.c | 39 ++++++++++----------------------------
 1 file changed, 10 insertions(+), 29 deletions(-)

diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c
index 056da6ee1a35..915d77785193 100644
--- a/drivers/xen/xenbus/xenbus_client.c
+++ b/drivers/xen/xenbus/xenbus_client.c
@@ -259,53 +259,34 @@ int xenbus_frontend_closed(struct xenbus_device *dev)
 }
 EXPORT_SYMBOL_GPL(xenbus_frontend_closed);
 
-/**
- * Return the path to the error node for the given device, or NULL on failure.
- * If the value returned is non-NULL, then it is the caller's to kfree.
- */
-static char *error_path(struct xenbus_device *dev)
-{
-	return kasprintf(GFP_KERNEL, "error/%s", dev->nodename);
-}
-
-
 static void xenbus_va_dev_error(struct xenbus_device *dev, int err,
 				const char *fmt, va_list ap)
 {
 	unsigned int len;
-	char *printf_buffer = NULL;
-	char *path_buffer = NULL;
+	char *printf_buffer;
+	char *path_buffer;
 
 #define PRINTF_BUFFER_SIZE 4096
+
 	printf_buffer = kmalloc(PRINTF_BUFFER_SIZE, GFP_KERNEL);
-	if (printf_buffer == NULL)
-		goto fail;
+	if (!printf_buffer)
+		return;
 
 	len = sprintf(printf_buffer, "%i ", -err);
-	vsnprintf(printf_buffer+len, PRINTF_BUFFER_SIZE-len, fmt, ap);
+	vsnprintf(printf_buffer + len, PRINTF_BUFFER_SIZE - len, fmt, ap);
 
 	dev_err(&dev->dev, "%s\n", printf_buffer);
 
-	path_buffer = error_path(dev);
-
-	if (path_buffer == NULL) {
+	path_buffer = kasprintf(GFP_KERNEL, "error/%s", dev->nodename);
+	if (!path_buffer ||
+	    xenbus_write(XBT_NIL, path_buffer, "error", printf_buffer))
 		dev_err(&dev->dev, "failed to write error node for %s (%s)\n",
-		       dev->nodename, printf_buffer);
-		goto fail;
-	}
+			dev->nodename, printf_buffer);
 
-	if (xenbus_write(XBT_NIL, path_buffer, "error", printf_buffer) != 0) {
-		dev_err(&dev->dev, "failed to write error node for %s (%s)\n",
-		       dev->nodename, printf_buffer);
-		goto fail;
-	}
-
-fail:
 	kfree(printf_buffer);
 	kfree(path_buffer);
 }
 
-
 /**
  * xenbus_dev_error
  * @dev: xenbus device
-- 
2.10.0.rc2.1.g053435c

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH] xenbus: Neaten xenbus_va_dev_error
@ 2017-02-08 11:33 ` Joe Perches
  0 siblings, 0 replies; 10+ messages in thread
From: Joe Perches @ 2017-02-08 11:33 UTC (permalink / raw)
  To: linux-kernel; +Cc: Juergen Gross, xen-devel, Boris Ostrovsky

This function error patch can be simplified, so do so.

Remove fail: label and somewhat obfuscating, used once "error_path"
function.

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/xen/xenbus/xenbus_client.c | 39 ++++++++++----------------------------
 1 file changed, 10 insertions(+), 29 deletions(-)

diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c
index 056da6ee1a35..915d77785193 100644
--- a/drivers/xen/xenbus/xenbus_client.c
+++ b/drivers/xen/xenbus/xenbus_client.c
@@ -259,53 +259,34 @@ int xenbus_frontend_closed(struct xenbus_device *dev)
 }
 EXPORT_SYMBOL_GPL(xenbus_frontend_closed);
 
-/**
- * Return the path to the error node for the given device, or NULL on failure.
- * If the value returned is non-NULL, then it is the caller's to kfree.
- */
-static char *error_path(struct xenbus_device *dev)
-{
-	return kasprintf(GFP_KERNEL, "error/%s", dev->nodename);
-}
-
-
 static void xenbus_va_dev_error(struct xenbus_device *dev, int err,
 				const char *fmt, va_list ap)
 {
 	unsigned int len;
-	char *printf_buffer = NULL;
-	char *path_buffer = NULL;
+	char *printf_buffer;
+	char *path_buffer;
 
 #define PRINTF_BUFFER_SIZE 4096
+
 	printf_buffer = kmalloc(PRINTF_BUFFER_SIZE, GFP_KERNEL);
-	if (printf_buffer == NULL)
-		goto fail;
+	if (!printf_buffer)
+		return;
 
 	len = sprintf(printf_buffer, "%i ", -err);
-	vsnprintf(printf_buffer+len, PRINTF_BUFFER_SIZE-len, fmt, ap);
+	vsnprintf(printf_buffer + len, PRINTF_BUFFER_SIZE - len, fmt, ap);
 
 	dev_err(&dev->dev, "%s\n", printf_buffer);
 
-	path_buffer = error_path(dev);
-
-	if (path_buffer == NULL) {
+	path_buffer = kasprintf(GFP_KERNEL, "error/%s", dev->nodename);
+	if (!path_buffer ||
+	    xenbus_write(XBT_NIL, path_buffer, "error", printf_buffer))
 		dev_err(&dev->dev, "failed to write error node for %s (%s)\n",
-		       dev->nodename, printf_buffer);
-		goto fail;
-	}
+			dev->nodename, printf_buffer);
 
-	if (xenbus_write(XBT_NIL, path_buffer, "error", printf_buffer) != 0) {
-		dev_err(&dev->dev, "failed to write error node for %s (%s)\n",
-		       dev->nodename, printf_buffer);
-		goto fail;
-	}
-
-fail:
 	kfree(printf_buffer);
 	kfree(path_buffer);
 }
 
-
 /**
  * xenbus_dev_error
  * @dev: xenbus device
-- 
2.10.0.rc2.1.g053435c


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] xenbus: Neaten xenbus_va_dev_error
  2017-02-08 11:33 ` Joe Perches
@ 2017-02-08 15:33   ` Boris Ostrovsky
  -1 siblings, 0 replies; 10+ messages in thread
From: Boris Ostrovsky @ 2017-02-08 15:33 UTC (permalink / raw)
  To: Joe Perches, linux-kernel; +Cc: Juergen Gross, xen-devel

On 02/08/2017 06:33 AM, Joe Perches wrote:
> This function error patch can be simplified, so do so.
>
> Remove fail: label and somewhat obfuscating, used once "error_path"
> function.
>
> Signed-off-by: Joe Perches <joe@perches.com>

Applied to for-linus-4.11.

-boris

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] xenbus: Neaten xenbus_va_dev_error
@ 2017-02-08 15:33   ` Boris Ostrovsky
  0 siblings, 0 replies; 10+ messages in thread
From: Boris Ostrovsky @ 2017-02-08 15:33 UTC (permalink / raw)
  To: Joe Perches, linux-kernel; +Cc: Juergen Gross, xen-devel

On 02/08/2017 06:33 AM, Joe Perches wrote:
> This function error patch can be simplified, so do so.
>
> Remove fail: label and somewhat obfuscating, used once "error_path"
> function.
>
> Signed-off-by: Joe Perches <joe@perches.com>

Applied to for-linus-4.11.

-boris

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] xenbus: Neaten xenbus_va_dev_error
  2017-02-08 15:33   ` Boris Ostrovsky
@ 2017-02-08 16:05     ` Joe Perches
  -1 siblings, 0 replies; 10+ messages in thread
From: Joe Perches @ 2017-02-08 16:05 UTC (permalink / raw)
  To: Boris Ostrovsky, linux-kernel; +Cc: Juergen Gross, xen-devel

On Wed, 2017-02-08 at 10:33 -0500, Boris Ostrovsky wrote:
> On 02/08/2017 06:33 AM, Joe Perches wrote:
> > This function error patch can be simplified, so do so.
> > 
> > Remove fail: label and somewhat obfuscating, used once "error_path"
> > function.

btw: I left it alone, but likely

#define PRINTF_BUFFER_SIZE 4096

is probably excessive as the maximum printk
buffer is 1024.

The xenbus_write might be longer though so
maybe it's OK to use 4096, but there is some
inequivalence there.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] xenbus: Neaten xenbus_va_dev_error
@ 2017-02-08 16:05     ` Joe Perches
  0 siblings, 0 replies; 10+ messages in thread
From: Joe Perches @ 2017-02-08 16:05 UTC (permalink / raw)
  To: Boris Ostrovsky, linux-kernel; +Cc: Juergen Gross, xen-devel

On Wed, 2017-02-08 at 10:33 -0500, Boris Ostrovsky wrote:
> On 02/08/2017 06:33 AM, Joe Perches wrote:
> > This function error patch can be simplified, so do so.
> > 
> > Remove fail: label and somewhat obfuscating, used once "error_path"
> > function.

btw: I left it alone, but likely

#define PRINTF_BUFFER_SIZE 4096

is probably excessive as the maximum printk
buffer is 1024.

The xenbus_write might be longer though so
maybe it's OK to use 4096, but there is some
inequivalence there.


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] xenbus: Neaten xenbus_va_dev_error
  2017-02-08 16:05     ` Joe Perches
@ 2017-02-08 17:14       ` Boris Ostrovsky
  -1 siblings, 0 replies; 10+ messages in thread
From: Boris Ostrovsky @ 2017-02-08 17:14 UTC (permalink / raw)
  To: Joe Perches, linux-kernel; +Cc: Juergen Gross, xen-devel

On 02/08/2017 11:05 AM, Joe Perches wrote:
> On Wed, 2017-02-08 at 10:33 -0500, Boris Ostrovsky wrote:
>> On 02/08/2017 06:33 AM, Joe Perches wrote:
>>> This function error patch can be simplified, so do so.
>>>
>>> Remove fail: label and somewhat obfuscating, used once "error_path"
>>> function.
> btw: I left it alone, but likely
>
> #define PRINTF_BUFFER_SIZE 4096
>
> is probably excessive as the maximum printk
> buffer is 1024.
>
> The xenbus_write might be longer though so
> maybe it's OK to use 4096, but there is some
> inequivalence there.
>

xenbus_write() handles writes up to 4K. However we are filling the
buffer with sprintf() which I assume is limited to 1K too so it indeed
doesn't seem useful to have PRINTF_BUFFER_SIZE set to 4.

-boris

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] xenbus: Neaten xenbus_va_dev_error
@ 2017-02-08 17:14       ` Boris Ostrovsky
  0 siblings, 0 replies; 10+ messages in thread
From: Boris Ostrovsky @ 2017-02-08 17:14 UTC (permalink / raw)
  To: Joe Perches, linux-kernel; +Cc: Juergen Gross, xen-devel

On 02/08/2017 11:05 AM, Joe Perches wrote:
> On Wed, 2017-02-08 at 10:33 -0500, Boris Ostrovsky wrote:
>> On 02/08/2017 06:33 AM, Joe Perches wrote:
>>> This function error patch can be simplified, so do so.
>>>
>>> Remove fail: label and somewhat obfuscating, used once "error_path"
>>> function.
> btw: I left it alone, but likely
>
> #define PRINTF_BUFFER_SIZE 4096
>
> is probably excessive as the maximum printk
> buffer is 1024.
>
> The xenbus_write might be longer though so
> maybe it's OK to use 4096, but there is some
> inequivalence there.
>

xenbus_write() handles writes up to 4K. However we are filling the
buffer with sprintf() which I assume is limited to 1K too so it indeed
doesn't seem useful to have PRINTF_BUFFER_SIZE set to 4.

-boris


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] xenbus: Neaten xenbus_va_dev_error
  2017-02-08 17:14       ` Boris Ostrovsky
@ 2017-02-08 18:20         ` Joe Perches
  -1 siblings, 0 replies; 10+ messages in thread
From: Joe Perches @ 2017-02-08 18:20 UTC (permalink / raw)
  To: Boris Ostrovsky, linux-kernel; +Cc: Juergen Gross, xen-devel

On Wed, 2017-02-08 at 12:14 -0500, Boris Ostrovsky wrote:
> On 02/08/2017 11:05 AM, Joe Perches wrote:
> > On Wed, 2017-02-08 at 10:33 -0500, Boris Ostrovsky wrote:
> > > On 02/08/2017 06:33 AM, Joe Perches wrote:
> > > > This function error patch can be simplified, so do so.
> > > > 
> > > > Remove fail: label and somewhat obfuscating, used once "error_path"
> > > > function.
> > 
> > btw: I left it alone, but likely
> > 
> > #define PRINTF_BUFFER_SIZE 4096
> > 
> > is probably excessive as the maximum printk
> > buffer is 1024.
> > 
> > The xenbus_write might be longer though so
> > maybe it's OK to use 4096, but there is some
> > inequivalence there.
> > 
> 
> xenbus_write() handles writes up to 4K. However we are filling the
> buffer with sprintf() which I assume is limited to 1K too

vsnprintf is bounded only by addressable memory. ie: (void *)-1

> so it indeed
> doesn't seem useful to have PRINTF_BUFFER_SIZE set to 4.
> 
> -boris
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] xenbus: Neaten xenbus_va_dev_error
@ 2017-02-08 18:20         ` Joe Perches
  0 siblings, 0 replies; 10+ messages in thread
From: Joe Perches @ 2017-02-08 18:20 UTC (permalink / raw)
  To: Boris Ostrovsky, linux-kernel; +Cc: Juergen Gross, xen-devel

On Wed, 2017-02-08 at 12:14 -0500, Boris Ostrovsky wrote:
> On 02/08/2017 11:05 AM, Joe Perches wrote:
> > On Wed, 2017-02-08 at 10:33 -0500, Boris Ostrovsky wrote:
> > > On 02/08/2017 06:33 AM, Joe Perches wrote:
> > > > This function error patch can be simplified, so do so.
> > > > 
> > > > Remove fail: label and somewhat obfuscating, used once "error_path"
> > > > function.
> > 
> > btw: I left it alone, but likely
> > 
> > #define PRINTF_BUFFER_SIZE 4096
> > 
> > is probably excessive as the maximum printk
> > buffer is 1024.
> > 
> > The xenbus_write might be longer though so
> > maybe it's OK to use 4096, but there is some
> > inequivalence there.
> > 
> 
> xenbus_write() handles writes up to 4K. However we are filling the
> buffer with sprintf() which I assume is limited to 1K too

vsnprintf is bounded only by addressable memory. ie: (void *)-1

> so it indeed
> doesn't seem useful to have PRINTF_BUFFER_SIZE set to 4.
> 
> -boris
> 

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-02-08 18:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-08 11:33 [PATCH] xenbus: Neaten xenbus_va_dev_error Joe Perches
2017-02-08 11:33 ` Joe Perches
2017-02-08 15:33 ` Boris Ostrovsky
2017-02-08 15:33   ` Boris Ostrovsky
2017-02-08 16:05   ` Joe Perches
2017-02-08 16:05     ` Joe Perches
2017-02-08 17:14     ` Boris Ostrovsky
2017-02-08 17:14       ` Boris Ostrovsky
2017-02-08 18:20       ` Joe Perches
2017-02-08 18:20         ` Joe Perches

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.