linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] vmbus: Reuse uuid_le_to_bin() helper
@ 2017-05-03 17:07 Andy Shevchenko
  2017-05-03 17:19 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2017-05-03 17:07 UTC (permalink / raw)
  To: K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, devel, linux-kernel
  Cc: Andy Shevchenko

Instead of open coded variant use generic helper to convert UUID strings
to binary format.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/hv/vmbus_drv.c | 51 ++++++++++----------------------------------------
 1 file changed, 10 insertions(+), 41 deletions(-)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index b41a2be778f6..fa2a6fa59480 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -608,40 +608,6 @@ static void vmbus_free_dynids(struct hv_driver *drv)
 	spin_unlock(&drv->dynids.lock);
 }
 
-/* Parse string of form: 1b4e28ba-2fa1-11d2-883f-b9a761bde3f */
-static int get_uuid_le(const char *str, uuid_le *uu)
-{
-	unsigned int b[16];
-	int i;
-
-	if (strlen(str) < 37)
-		return -1;
-
-	for (i = 0; i < 36; i++) {
-		switch (i) {
-		case 8: case 13: case 18: case 23:
-			if (str[i] != '-')
-				return -1;
-			break;
-		default:
-			if (!isxdigit(str[i]))
-				return -1;
-		}
-	}
-
-	/* unparse little endian output byte order */
-	if (sscanf(str,
-		   "%2x%2x%2x%2x-%2x%2x-%2x%2x-%2x%2x-%2x%2x%2x%2x%2x%2x",
-		   &b[3], &b[2], &b[1], &b[0],
-		   &b[5], &b[4], &b[7], &b[6], &b[8], &b[9],
-		   &b[10], &b[11], &b[12], &b[13], &b[14], &b[15]) != 16)
-		return -1;
-
-	for (i = 0; i < 16; i++)
-		uu->b[i] = b[i];
-	return 0;
-}
-
 /*
  * store_new_id - sysfs frontend to vmbus_add_dynid()
  *
@@ -651,11 +617,12 @@ static ssize_t new_id_store(struct device_driver *driver, const char *buf,
 			    size_t count)
 {
 	struct hv_driver *drv = drv_to_hv_drv(driver);
-	uuid_le guid = NULL_UUID_LE;
+	uuid_le guid;
 	ssize_t retval;
 
-	if (get_uuid_le(buf, &guid) != 0)
-		return -EINVAL;
+	retval = uuid_le_to_bin(buf, &guid);
+	if (retval)
+	       return retval;
 
 	if (hv_vmbus_get_id(drv, &guid))
 		return -EEXIST;
@@ -677,12 +644,14 @@ static ssize_t remove_id_store(struct device_driver *driver, const char *buf,
 {
 	struct hv_driver *drv = drv_to_hv_drv(driver);
 	struct vmbus_dynid *dynid, *n;
-	uuid_le guid = NULL_UUID_LE;
-	size_t retval = -ENODEV;
+	uuid_le guid;
+	ssize_t retval;
 
-	if (get_uuid_le(buf, &guid))
-		return -EINVAL;
+	retval = uuid_le_to_bin(buf, &guid);
+	if (retval)
+	       return retval;
 
+	retval = -ENODEV;
 	spin_lock(&drv->dynids.lock);
 	list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) {
 		struct hv_vmbus_device_id *id = &dynid->id;
-- 
2.11.0

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

* Re: [PATCH v1] vmbus: Reuse uuid_le_to_bin() helper
  2017-05-03 17:07 [PATCH v1] vmbus: Reuse uuid_le_to_bin() helper Andy Shevchenko
@ 2017-05-03 17:19 ` Andy Shevchenko
  2017-05-04  8:03   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2017-05-03 17:19 UTC (permalink / raw)
  To: K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, devel, linux-kernel

On Wed, 2017-05-03 at 20:07 +0300, Andy Shevchenko wrote:
> Instead of open coded variant use generic helper to convert UUID
> strings
> to binary format.

> @@ -677,12 +644,14 @@ static ssize_t remove_id_store(struct
> device_driver *driver, const char *buf,
>  {
>  	struct hv_driver *drv = drv_to_hv_drv(driver);
>  	struct vmbus_dynid *dynid, *n;
> 

> -	size_t retval = -ENODEV;
> 
> +	ssize_t retval;

Just noticed, I'm fixing a bug here as well.

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

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

* Re: [PATCH v1] vmbus: Reuse uuid_le_to_bin() helper
  2017-05-03 17:19 ` Andy Shevchenko
@ 2017-05-04  8:03   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2017-05-04  8:03 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, devel, linux-kernel

On Wed, May 03, 2017 at 08:19:22PM +0300, Andy Shevchenko wrote:
> On Wed, 2017-05-03 at 20:07 +0300, Andy Shevchenko wrote:
> > Instead of open coded variant use generic helper to convert UUID
> > strings
> > to binary format.
> 
> > @@ -677,12 +644,14 @@ static ssize_t remove_id_store(struct
> > device_driver *driver, const char *buf,
> >  {
> >  	struct hv_driver *drv = drv_to_hv_drv(driver);
> >  	struct vmbus_dynid *dynid, *n;
> > 
> 
> > -	size_t retval = -ENODEV;
> > 
> > +	ssize_t retval;
> 
> Just noticed, I'm fixing a bug here as well.

It doesn't affect runtime.  You can store negatives in unsigned types so
long as they're uint or larger.

regards,
dan carpenter

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

end of thread, other threads:[~2017-05-04  8:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-03 17:07 [PATCH v1] vmbus: Reuse uuid_le_to_bin() helper Andy Shevchenko
2017-05-03 17:19 ` Andy Shevchenko
2017-05-04  8:03   ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).