Commit ecc3099002c1cc87e9e4b3dc5fdf7821828f6733
Committed by
Linus Torvalds
1 parent
3094141c65
Exists in
master
and in
4 other branches
drivers: scsi: use newly introduced hex_to_bin() method
Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Cc: Adaptec OEM Raid Solutions <aacraid@adaptec.com> Cc: "James E.J. Bottomley" <James.Bottomley@suse.de> Cc: James Smart <james.smart@emulex.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 3 changed files with 19 additions and 21 deletions Side-by-side Diff
drivers/scsi/aacraid/rx.c
... | ... | @@ -352,9 +352,8 @@ |
352 | 352 | pci_free_consistent(dev->pdev, sizeof(struct POSTSTATUS), |
353 | 353 | post, paddr); |
354 | 354 | if (likely((buffer[0] == '0') && ((buffer[1] == 'x') || (buffer[1] == 'X')))) { |
355 | - ret = (buffer[2] <= '9') ? (buffer[2] - '0') : (buffer[2] - 'A' + 10); | |
356 | - ret <<= 4; | |
357 | - ret += (buffer[3] <= '9') ? (buffer[3] - '0') : (buffer[3] - 'A' + 10); | |
355 | + ret = (hex_to_bin(buffer[2]) << 4) + | |
356 | + hex_to_bin(buffer[3]); | |
358 | 357 | } |
359 | 358 | pci_free_consistent(dev->pdev, 512, buffer, baddr); |
360 | 359 | return ret; |
drivers/scsi/lpfc/lpfc_attr.c
... | ... | @@ -25,6 +25,7 @@ |
25 | 25 | #include <linux/interrupt.h> |
26 | 26 | #include <linux/aer.h> |
27 | 27 | #include <linux/gfp.h> |
28 | +#include <linux/kernel.h> | |
28 | 29 | |
29 | 30 | #include <scsi/scsi.h> |
30 | 31 | #include <scsi/scsi_device.h> |
... | ... | @@ -1795,12 +1796,11 @@ |
1795 | 1796 | |
1796 | 1797 | /* Validate and store the new name */ |
1797 | 1798 | for (i=0, j=0; i < 16; i++) { |
1798 | - if ((*buf >= 'a') && (*buf <= 'f')) | |
1799 | - j = ((j << 4) | ((*buf++ -'a') + 10)); | |
1800 | - else if ((*buf >= 'A') && (*buf <= 'F')) | |
1801 | - j = ((j << 4) | ((*buf++ -'A') + 10)); | |
1802 | - else if ((*buf >= '0') && (*buf <= '9')) | |
1803 | - j = ((j << 4) | (*buf++ -'0')); | |
1799 | + int value; | |
1800 | + | |
1801 | + value = hex_to_bin(*buf++); | |
1802 | + if (value >= 0) | |
1803 | + j = (j << 4) | value; | |
1804 | 1804 | else |
1805 | 1805 | return -EINVAL; |
1806 | 1806 | if (i % 2) { |
... | ... | @@ -1888,12 +1888,11 @@ |
1888 | 1888 | |
1889 | 1889 | /* Validate and store the new name */ |
1890 | 1890 | for (i=0, j=0; i < 16; i++) { |
1891 | - if ((*buf >= 'a') && (*buf <= 'f')) | |
1892 | - j = ((j << 4) | ((*buf++ -'a') + 10)); | |
1893 | - else if ((*buf >= 'A') && (*buf <= 'F')) | |
1894 | - j = ((j << 4) | ((*buf++ -'A') + 10)); | |
1895 | - else if ((*buf >= '0') && (*buf <= '9')) | |
1896 | - j = ((j << 4) | (*buf++ -'0')); | |
1891 | + int value; | |
1892 | + | |
1893 | + value = hex_to_bin(*buf++); | |
1894 | + if (value >= 0) | |
1895 | + j = (j << 4) | value; | |
1897 | 1896 | else |
1898 | 1897 | return -EINVAL; |
1899 | 1898 | if (i % 2) { |
drivers/scsi/scsi_transport_fc.c
... | ... | @@ -29,6 +29,7 @@ |
29 | 29 | #include <linux/init.h> |
30 | 30 | #include <linux/slab.h> |
31 | 31 | #include <linux/delay.h> |
32 | +#include <linux/kernel.h> | |
32 | 33 | #include <scsi/scsi_device.h> |
33 | 34 | #include <scsi/scsi_host.h> |
34 | 35 | #include <scsi/scsi_transport.h> |
... | ... | @@ -1730,12 +1731,11 @@ |
1730 | 1731 | |
1731 | 1732 | /* Validate and store the new name */ |
1732 | 1733 | for (i=0, j=0; i < 16; i++) { |
1733 | - if ((*ns >= 'a') && (*ns <= 'f')) | |
1734 | - j = ((j << 4) | ((*ns++ -'a') + 10)); | |
1735 | - else if ((*ns >= 'A') && (*ns <= 'F')) | |
1736 | - j = ((j << 4) | ((*ns++ -'A') + 10)); | |
1737 | - else if ((*ns >= '0') && (*ns <= '9')) | |
1738 | - j = ((j << 4) | (*ns++ -'0')); | |
1734 | + int value; | |
1735 | + | |
1736 | + value = hex_to_bin(*ns++); | |
1737 | + if (value >= 0) | |
1738 | + j = (j << 4) | value; | |
1739 | 1739 | else |
1740 | 1740 | return -EINVAL; |
1741 | 1741 | if (i % 2) { |