Skip to contentSkip to conversation

libsas: remove private hex2bin() implementation

PATCH Applied Andy Shevchenko 3 participants 3 messages Dec 19, 2017 – Jan 4, 2018

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

PATCH 1/1 libsas: remove private hex2bin() implementation

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

Cc Christoph Hellwig <[email protected]>
---
 drivers/scsi/libsas/sas_scsi_host.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)
drivers/scsi/libsas/sas_scsi_host.c +4 -16
index 58476b728c57..626727207889 100644
@@ -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);
Signature · 1 line
2.15.1
Tested-by on v1 1/1
#1 lore raw
Quoted 5 lines · Andy Shevchenko

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

Cc Christoph Hellwig <[email protected]>
Quoted 49 lines
---
  drivers/scsi/libsas/sas_scsi_host.c | 20 ++++----------------
  1 file changed, 4 insertions(+), 16 deletions(-)
drivers/scsi/libsas/sas_scsi_host.c +4 -16
index 58476b728c57..626727207889 100644
@@ -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 lore raw
In reply to Andy Shevchenko

Andy,

Quoted 2 lines

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!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering