All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] libsas: remove private hex2bin() implementation
@ 2017-12-19 17:37 Andy Shevchenko
  2018-01-02 11:16 ` chenxiang (M)
  2018-01-04  3:41 ` Martin K. Petersen
  0 siblings, 2 replies; 3+ messages in thread
From: Andy Shevchenko @ 2017-12-19 17:37 UTC (permalink / raw)
  To: James E.J. Bottomley, Martin K. Petersen, linux-scsi
  Cc: Andy Shevchenko, Christoph Hellwig

The function sas_parse_addr() could be easily substituted by hex2bin() which is
in kernel library code.

Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/scsi/libsas/sas_scsi_host.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
index 58476b728c57..626727207889 100644
--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -27,6 +27,7 @@
 #include <linux/firmware.h>
 #include <linux/export.h>
 #include <linux/ctype.h>
+#include <linux/kernel.h>
 
 #include "sas_internal.h"
 
@@ -946,21 +947,6 @@ void sas_target_destroy(struct scsi_target *starget)
 	sas_put_device(found_dev);
 }
 
-static void sas_parse_addr(u8 *sas_addr, const char *p)
-{
-	int i;
-	for (i = 0; i < SAS_ADDR_SIZE; i++) {
-		u8 h, l;
-		if (!*p)
-			break;
-		h = isdigit(*p) ? *p-'0' : toupper(*p)-'A'+10;
-		p++;
-		l = isdigit(*p) ? *p-'0' : toupper(*p)-'A'+10;
-		p++;
-		sas_addr[i] = (h<<4) | l;
-	}
-}
-
 #define SAS_STRING_ADDR_SIZE	16
 
 int sas_request_addr(struct Scsi_Host *shost, u8 *addr)
@@ -977,7 +963,9 @@ int sas_request_addr(struct Scsi_Host *shost, u8 *addr)
 		goto out;
 	}
 
-	sas_parse_addr(addr, fw->data);
+	res = hex2bin(addr, fw->data, strnlen(fw->data, SAS_ADDR_SIZE * 2) / 2);
+	if (res)
+		goto out;
 
 out:
 	release_firmware(fw);
-- 
2.15.1

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

* Re: [PATCH v1] libsas: remove private hex2bin() implementation
  2017-12-19 17:37 [PATCH v1] libsas: remove private hex2bin() implementation Andy Shevchenko
@ 2018-01-02 11:16 ` chenxiang (M)
  2018-01-04  3:41 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: chenxiang (M) @ 2018-01-02 11:16 UTC (permalink / raw)
  To: Andy Shevchenko, James E.J. Bottomley, Martin K. Petersen,
	linux-scsi
  Cc: Christoph Hellwig

在 2017/12/20 1:37, Andy Shevchenko 写道:
> The function sas_parse_addr() could be easily substituted by hex2bin() which is
> in kernel library code.
>
> Cc: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Tested-by: Xiang Chen <chenxiang66@hisilicon.com>

> ---
>   drivers/scsi/libsas/sas_scsi_host.c | 20 ++++----------------
>   1 file changed, 4 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
> index 58476b728c57..626727207889 100644
> --- a/drivers/scsi/libsas/sas_scsi_host.c
> +++ b/drivers/scsi/libsas/sas_scsi_host.c
> @@ -27,6 +27,7 @@
>   #include <linux/firmware.h>
>   #include <linux/export.h>
>   #include <linux/ctype.h>
> +#include <linux/kernel.h>
>   
>   #include "sas_internal.h"
>   
> @@ -946,21 +947,6 @@ void sas_target_destroy(struct scsi_target *starget)
>   	sas_put_device(found_dev);
>   }
>   
> -static void sas_parse_addr(u8 *sas_addr, const char *p)
> -{
> -	int i;
> -	for (i = 0; i < SAS_ADDR_SIZE; i++) {
> -		u8 h, l;
> -		if (!*p)
> -			break;
> -		h = isdigit(*p) ? *p-'0' : toupper(*p)-'A'+10;
> -		p++;
> -		l = isdigit(*p) ? *p-'0' : toupper(*p)-'A'+10;
> -		p++;
> -		sas_addr[i] = (h<<4) | l;
> -	}
> -}
> -
>   #define SAS_STRING_ADDR_SIZE	16
>   
>   int sas_request_addr(struct Scsi_Host *shost, u8 *addr)
> @@ -977,7 +963,9 @@ int sas_request_addr(struct Scsi_Host *shost, u8 *addr)
>   		goto out;
>   	}
>   
> -	sas_parse_addr(addr, fw->data);
> +	res = hex2bin(addr, fw->data, strnlen(fw->data, SAS_ADDR_SIZE * 2) / 2);
> +	if (res)
> +		goto out;
>   
>   out:
>   	release_firmware(fw);

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

* Re: [PATCH v1] libsas: remove private hex2bin() implementation
  2017-12-19 17:37 [PATCH v1] libsas: remove private hex2bin() implementation Andy Shevchenko
  2018-01-02 11:16 ` chenxiang (M)
@ 2018-01-04  3:41 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2018-01-04  3:41 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi,
	Christoph Hellwig


Andy,

> The function sas_parse_addr() could be easily substituted by hex2bin()
> which is in kernel library code.

Applied to 4.16/scsi-queue. Thank you!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2018-01-04  3:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-19 17:37 [PATCH v1] libsas: remove private hex2bin() implementation Andy Shevchenko
2018-01-02 11:16 ` chenxiang (M)
2018-01-04  3:41 ` Martin K. Petersen

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.