* [PATCH 0/3] SCSI device blacklist handling improvements
@ 2017-12-04 18:36 Bart Van Assche
2017-12-04 18:36 ` [PATCH 1/3] scsi_get_device_flags_keyed(): Always return device flags Bart Van Assche
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Bart Van Assche @ 2017-12-04 18:36 UTC (permalink / raw)
To: Martin K . Petersen, James E . J . Bottomley; +Cc: linux-scsi, Bart Van Assche
Hello Martin,
These three patches is what I came up with after having reviewed recent
changes in the code for handling blacklist flags handling. Please consider
these patches for kernel v4.16.
Note: since patch "Use 'blist_flags_t' for scsi_devinfo flags" is not yet
in the 4.16/scsi-queue branch I have developed these patches on top of a
merge of the v4.15-rc1 release and your 4.16/scsi-queue branch.
Thanks,
Bart.
Bart Van Assche (3):
scsi_get_device_flags_keyed(): Always return device flags
Use blist_flags_t consistently
Introduce scsi_devinfo_key enumeration type
drivers/scsi/scsi_devinfo.c | 29 ++++++++++++-----------------
drivers/scsi/scsi_priv.h | 14 ++++++++------
drivers/scsi/scsi_scan.c | 13 +++++++------
drivers/scsi/scsi_sysfs.c | 4 ++--
drivers/scsi/scsi_transport_spi.c | 12 +++++++-----
5 files changed, 36 insertions(+), 36 deletions(-)
--
2.15.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/3] scsi_get_device_flags_keyed(): Always return device flags
2017-12-04 18:36 [PATCH 0/3] SCSI device blacklist handling improvements Bart Van Assche
@ 2017-12-04 18:36 ` Bart Van Assche
2017-12-04 18:36 ` [PATCH 2/3] Use blist_flags_t consistently Bart Van Assche
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Bart Van Assche @ 2017-12-04 18:36 UTC (permalink / raw)
To: Martin K . Petersen, James E . J . Bottomley
Cc: linux-scsi, Bart Van Assche, Christoph Hellwig, Hannes Reinecke,
Johannes Thumshirn
Since scsi_get_device_flags_keyed() callers do not check whether or
not the returned value is an error code, change that function such
that it returns a flags value even if the 'key' argument is invalid.
Note: since commit 28a0bc4120d3 ("scsi: sd: Implement blacklist
option for WRITE SAME w/ UNMAP") bit 31 is a valid device information
flag so checking whether bit 31 is set in the return value is not
sufficient to tell the difference between an error code and a flags
value.
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
---
drivers/scsi/scsi_devinfo.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c
index 78d4aa8df675..2fed250e87bf 100644
--- a/drivers/scsi/scsi_devinfo.c
+++ b/drivers/scsi/scsi_devinfo.c
@@ -599,17 +599,12 @@ blist_flags_t scsi_get_device_flags_keyed(struct scsi_device *sdev,
int key)
{
struct scsi_dev_info_list *devinfo;
- int err;
devinfo = scsi_dev_info_list_find(vendor, model, key);
if (!IS_ERR(devinfo))
return devinfo->flags;
- err = PTR_ERR(devinfo);
- if (err != -ENOENT)
- return err;
-
- /* nothing found, return nothing */
+ /* key or device not found: return nothing */
if (key != SCSI_DEVINFO_GLOBAL)
return 0;
--
2.15.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] Use blist_flags_t consistently
2017-12-04 18:36 [PATCH 0/3] SCSI device blacklist handling improvements Bart Van Assche
2017-12-04 18:36 ` [PATCH 1/3] scsi_get_device_flags_keyed(): Always return device flags Bart Van Assche
@ 2017-12-04 18:36 ` Bart Van Assche
2017-12-04 18:36 ` [PATCH 3/3] Introduce scsi_devinfo_key enumeration type Bart Van Assche
2017-12-07 2:03 ` [PATCH 0/3] SCSI device blacklist handling improvements Martin K. Petersen
3 siblings, 0 replies; 7+ messages in thread
From: Bart Van Assche @ 2017-12-04 18:36 UTC (permalink / raw)
To: Martin K . Petersen, James E . J . Bottomley
Cc: linux-scsi, Bart Van Assche, Christoph Hellwig, Hannes Reinecke,
Johannes Thumshirn
Use the type blist_flags_t for all variables that represent blacklist
flags. Additionally, suppress recently introduced sparse warnings related
to blacklist flags.
Fixes: commit c6b54164508a ("scsi: Use 'blist_flags_t' for scsi_devinfo flags")
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
---
drivers/scsi/scsi_devinfo.c | 8 +++-----
drivers/scsi/scsi_scan.c | 13 +++++++------
drivers/scsi/scsi_sysfs.c | 4 ++--
drivers/scsi/scsi_transport_spi.c | 12 +++++++-----
4 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c
index 2fed250e87bf..4b33c001ae23 100644
--- a/drivers/scsi/scsi_devinfo.c
+++ b/drivers/scsi/scsi_devinfo.c
@@ -382,10 +382,8 @@ int scsi_dev_info_list_add_keyed(int compatible, char *vendor, char *model,
model, compatible);
if (strflags)
- devinfo->flags = simple_strtoul(strflags, NULL, 0);
- else
- devinfo->flags = flags;
-
+ flags = (__force blist_flags_t)simple_strtoul(strflags, NULL, 0);
+ devinfo->flags = flags;
devinfo->compatible = compatible;
if (compatible)
@@ -612,7 +610,7 @@ blist_flags_t scsi_get_device_flags_keyed(struct scsi_device *sdev,
if (sdev->sdev_bflags)
return sdev->sdev_bflags;
- return scsi_default_dev_flags;
+ return (__force blist_flags_t)scsi_default_dev_flags;
}
EXPORT_SYMBOL(scsi_get_device_flags_keyed);
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index be5e919db0e8..0880d975eed3 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -770,7 +770,7 @@ static int scsi_probe_lun(struct scsi_device *sdev, unsigned char *inq_result,
* SCSI_SCAN_LUN_PRESENT: a new scsi_device was allocated and initialized
**/
static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
- int *bflags, int async)
+ blist_flags_t *bflags, int async)
{
int ret;
@@ -1049,14 +1049,15 @@ static unsigned char *scsi_inq_str(unsigned char *buf, unsigned char *inq,
* - SCSI_SCAN_LUN_PRESENT: a new scsi_device was allocated and initialized
**/
static int scsi_probe_and_add_lun(struct scsi_target *starget,
- u64 lun, int *bflagsp,
+ u64 lun, blist_flags_t *bflagsp,
struct scsi_device **sdevp,
enum scsi_scan_mode rescan,
void *hostdata)
{
struct scsi_device *sdev;
unsigned char *result;
- int bflags, res = SCSI_SCAN_NO_RESPONSE, result_len = 256;
+ blist_flags_t bflags;
+ int res = SCSI_SCAN_NO_RESPONSE, result_len = 256;
struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
/*
@@ -1201,7 +1202,7 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget,
* Modifies sdevscan->lun.
**/
static void scsi_sequential_lun_scan(struct scsi_target *starget,
- int bflags, int scsi_level,
+ blist_flags_t bflags, int scsi_level,
enum scsi_scan_mode rescan)
{
uint max_dev_lun;
@@ -1292,7 +1293,7 @@ static void scsi_sequential_lun_scan(struct scsi_target *starget,
* 0: scan completed (or no memory, so further scanning is futile)
* 1: could not scan with REPORT LUN
**/
-static int scsi_report_lun_scan(struct scsi_target *starget, int bflags,
+static int scsi_report_lun_scan(struct scsi_target *starget, blist_flags_t bflags,
enum scsi_scan_mode rescan)
{
unsigned char scsi_cmd[MAX_COMMAND_SIZE];
@@ -1538,7 +1539,7 @@ static void __scsi_scan_target(struct device *parent, unsigned int channel,
unsigned int id, u64 lun, enum scsi_scan_mode rescan)
{
struct Scsi_Host *shost = dev_to_shost(parent);
- int bflags = 0;
+ blist_flags_t bflags = 0;
int res;
struct scsi_target *starget;
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 50e7d7e4a861..6ee964643531 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -967,7 +967,7 @@ sdev_show_wwid(struct device *dev, struct device_attribute *attr,
}
static DEVICE_ATTR(wwid, S_IRUGO, sdev_show_wwid, NULL);
-#define BLIST_FLAG_NAME(name) [ilog2(BLIST_##name)] = #name
+#define BLIST_FLAG_NAME(name) [ilog2((__force u32)BLIST_##name)] = #name
static const char *const sdev_bflags_name[] = {
#include "scsi_devinfo_tbl.c"
};
@@ -984,7 +984,7 @@ sdev_show_blacklist(struct device *dev, struct device_attribute *attr,
for (i = 0; i < sizeof(sdev->sdev_bflags) * BITS_PER_BYTE; i++) {
const char *name = NULL;
- if (!(sdev->sdev_bflags & BIT(i)))
+ if (!((__force u32)sdev->sdev_bflags & BIT(i)))
continue;
if (i < ARRAY_SIZE(sdev_bflags_name) && sdev_bflags_name[i])
name = sdev_bflags_name[i];
diff --git a/drivers/scsi/scsi_transport_spi.c b/drivers/scsi/scsi_transport_spi.c
index d0219e36080c..10ebb213ddb3 100644
--- a/drivers/scsi/scsi_transport_spi.c
+++ b/drivers/scsi/scsi_transport_spi.c
@@ -50,14 +50,14 @@
/* Our blacklist flags */
enum {
- SPI_BLIST_NOIUS = 0x1,
+ SPI_BLIST_NOIUS = (__force blist_flags_t)0x1,
};
/* blacklist table, modelled on scsi_devinfo.c */
static struct {
char *vendor;
char *model;
- unsigned flags;
+ blist_flags_t flags;
} spi_static_device_list[] __initdata = {
{"HP", "Ultrium 3-SCSI", SPI_BLIST_NOIUS },
{"IBM", "ULTRIUM-TD3", SPI_BLIST_NOIUS },
@@ -221,9 +221,11 @@ static int spi_device_configure(struct transport_container *tc,
{
struct scsi_device *sdev = to_scsi_device(dev);
struct scsi_target *starget = sdev->sdev_target;
- unsigned bflags = scsi_get_device_flags_keyed(sdev, &sdev->inquiry[8],
- &sdev->inquiry[16],
- SCSI_DEVINFO_SPI);
+ blist_flags_t bflags;
+
+ bflags = scsi_get_device_flags_keyed(sdev, &sdev->inquiry[8],
+ &sdev->inquiry[16],
+ SCSI_DEVINFO_SPI);
/* Populate the target capability fields with the values
* gleaned from the device inquiry */
--
2.15.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] Introduce scsi_devinfo_key enumeration type
2017-12-04 18:36 [PATCH 0/3] SCSI device blacklist handling improvements Bart Van Assche
2017-12-04 18:36 ` [PATCH 1/3] scsi_get_device_flags_keyed(): Always return device flags Bart Van Assche
2017-12-04 18:36 ` [PATCH 2/3] Use blist_flags_t consistently Bart Van Assche
@ 2017-12-04 18:36 ` Bart Van Assche
2017-12-07 2:03 ` [PATCH 0/3] SCSI device blacklist handling improvements Martin K. Petersen
3 siblings, 0 replies; 7+ messages in thread
From: Bart Van Assche @ 2017-12-04 18:36 UTC (permalink / raw)
To: Martin K . Petersen, James E . J . Bottomley
Cc: linux-scsi, Bart Van Assche, Christoph Hellwig, Hannes Reinecke,
Johannes Thumshirn
Since symbolic names for the device information keys alread exist,
associate an enumeration type with these symbolic values. This change
makes it clear what the valid values for the 'key' arguments are.
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
---
drivers/scsi/scsi_devinfo.c | 14 ++++++++------
drivers/scsi/scsi_priv.h | 14 ++++++++------
2 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c
index 4b33c001ae23..82bc807e1d50 100644
--- a/drivers/scsi/scsi_devinfo.c
+++ b/drivers/scsi/scsi_devinfo.c
@@ -361,7 +361,8 @@ static int scsi_dev_info_list_add(int compatible, char *vendor, char *model,
* Returns: 0 OK, -error on failure.
**/
int scsi_dev_info_list_add_keyed(int compatible, char *vendor, char *model,
- char *strflags, blist_flags_t flags, int key)
+ char *strflags, blist_flags_t flags,
+ enum scsi_devinfo_key key)
{
struct scsi_dev_info_list *devinfo;
struct scsi_dev_info_list_table *devinfo_table =
@@ -410,7 +411,7 @@ EXPORT_SYMBOL(scsi_dev_info_list_add_keyed);
* Returns: pointer to matching entry, or ERR_PTR on failure.
**/
static struct scsi_dev_info_list *scsi_dev_info_list_find(const char *vendor,
- const char *model, int key)
+ const char *model, enum scsi_devinfo_key key)
{
struct scsi_dev_info_list *devinfo;
struct scsi_dev_info_list_table *devinfo_table =
@@ -492,7 +493,8 @@ static struct scsi_dev_info_list *scsi_dev_info_list_find(const char *vendor,
*
* Returns: 0 OK, -error on failure.
**/
-int scsi_dev_info_list_del_keyed(char *vendor, char *model, int key)
+int scsi_dev_info_list_del_keyed(char *vendor, char *model,
+ enum scsi_devinfo_key key)
{
struct scsi_dev_info_list *found;
@@ -594,7 +596,7 @@ blist_flags_t scsi_get_device_flags(struct scsi_device *sdev,
blist_flags_t scsi_get_device_flags_keyed(struct scsi_device *sdev,
const unsigned char *vendor,
const unsigned char *model,
- int key)
+ enum scsi_devinfo_key key)
{
struct scsi_dev_info_list *devinfo;
@@ -776,7 +778,7 @@ void scsi_exit_devinfo(void)
* Adds the requested list, returns zero on success, -EEXIST if the
* key is already registered to a list, or other error on failure.
*/
-int scsi_dev_info_add_list(int key, const char *name)
+int scsi_dev_info_add_list(enum scsi_devinfo_key key, const char *name)
{
struct scsi_dev_info_list_table *devinfo_table =
scsi_devinfo_lookup_by_key(key);
@@ -808,7 +810,7 @@ EXPORT_SYMBOL(scsi_dev_info_add_list);
* frees the list itself. Returns 0 on success or -EINVAL if the key
* can't be found.
*/
-int scsi_dev_info_remove_list(int key)
+int scsi_dev_info_remove_list(enum scsi_devinfo_key key)
{
struct list_head *lh, *lh_next;
struct scsi_dev_info_list_table *devinfo_table =
diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h
index a5946cd64caa..61024db5953d 100644
--- a/drivers/scsi/scsi_priv.h
+++ b/drivers/scsi/scsi_priv.h
@@ -45,7 +45,7 @@ static inline void scsi_log_completion(struct scsi_cmnd *cmd, int disposition)
/* scsi_devinfo.c */
/* list of keys for the lists */
-enum {
+enum scsi_devinfo_key {
SCSI_DEVINFO_GLOBAL = 0,
SCSI_DEVINFO_SPI,
};
@@ -56,13 +56,15 @@ extern blist_flags_t scsi_get_device_flags(struct scsi_device *sdev,
extern blist_flags_t scsi_get_device_flags_keyed(struct scsi_device *sdev,
const unsigned char *vendor,
const unsigned char *model,
- int key);
+ enum scsi_devinfo_key key);
extern int scsi_dev_info_list_add_keyed(int compatible, char *vendor,
char *model, char *strflags,
- blist_flags_t flags, int key);
-extern int scsi_dev_info_list_del_keyed(char *vendor, char *model, int key);
-extern int scsi_dev_info_add_list(int key, const char *name);
-extern int scsi_dev_info_remove_list(int key);
+ blist_flags_t flags,
+ enum scsi_devinfo_key key);
+extern int scsi_dev_info_list_del_keyed(char *vendor, char *model,
+ enum scsi_devinfo_key key);
+extern int scsi_dev_info_add_list(enum scsi_devinfo_key key, const char *name);
+extern int scsi_dev_info_remove_list(enum scsi_devinfo_key key);
extern int __init scsi_init_devinfo(void);
extern void scsi_exit_devinfo(void);
--
2.15.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/3] SCSI device blacklist handling improvements
2017-12-04 18:36 [PATCH 0/3] SCSI device blacklist handling improvements Bart Van Assche
` (2 preceding siblings ...)
2017-12-04 18:36 ` [PATCH 3/3] Introduce scsi_devinfo_key enumeration type Bart Van Assche
@ 2017-12-07 2:03 ` Martin K. Petersen
2017-12-07 17:34 ` Bart Van Assche
3 siblings, 1 reply; 7+ messages in thread
From: Martin K. Petersen @ 2017-12-07 2:03 UTC (permalink / raw)
To: Bart Van Assche; +Cc: Martin K . Petersen, James E . J . Bottomley, linux-scsi
Bart,
> These three patches is what I came up with after having reviewed
> recent changes in the code for handling blacklist flags
> handling. Please consider these patches for kernel v4.16.
I applied 1 and 3 to 4.16/scsi-queue. I am still not a fan of forcing
u32. That's a recipe for disaster when we add the next flag.
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/3] SCSI device blacklist handling improvements
2017-12-07 2:03 ` [PATCH 0/3] SCSI device blacklist handling improvements Martin K. Petersen
@ 2017-12-07 17:34 ` Bart Van Assche
2017-12-08 1:10 ` Martin K. Petersen
0 siblings, 1 reply; 7+ messages in thread
From: Bart Van Assche @ 2017-12-07 17:34 UTC (permalink / raw)
To: martin.petersen@oracle.com
Cc: jejb@linux.vnet.ibm.com, linux-scsi@vger.kernel.org
On Wed, 2017-12-06 at 21:03 -0500, Martin K. Petersen wrote:
> > These three patches is what I came up with after having reviewed
> > recent changes in the code for handling blacklist flags
> > handling. Please consider these patches for kernel v4.16.
>
> I applied 1 and 3 to 4.16/scsi-queue. I am still not a fan of forcing
> u32. That's a recipe for disaster when we add the next flag.
Hello Martin,
Are you perhaps referring to the five __force casts? If so, do you have a
suggestion for avoiding that sparse reports false positive warnings on the
conversions between int and blist_flags_t? The only approach I can think of
to reduce the number of __force casts is to embed these __force casts into
two helper functions - one for the conversion from int to blist_flags_t and
one for the conversion the other way around.
Thanks,
Bart.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/3] SCSI device blacklist handling improvements
2017-12-07 17:34 ` Bart Van Assche
@ 2017-12-08 1:10 ` Martin K. Petersen
0 siblings, 0 replies; 7+ messages in thread
From: Martin K. Petersen @ 2017-12-08 1:10 UTC (permalink / raw)
To: Bart Van Assche
Cc: martin.petersen@oracle.com, jejb@linux.vnet.ibm.com,
linux-scsi@vger.kernel.org
Bart,
> Are you perhaps referring to the five __force casts? If so, do you
> have a suggestion for avoiding that sparse reports false positive
> warnings on the conversions between int and blist_flags_t? The only
> approach I can think of to reduce the number of __force casts is to
> embed these __force casts into two helper functions - one for the
> conversion from int to blist_flags_t and one for the conversion the
> other way around.
blist_flags_t is an unsigned int, you are forcing it to u32 two
places. That's a problem waiting to happen next time we add a blacklist
flag.
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-12-08 1:10 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-04 18:36 [PATCH 0/3] SCSI device blacklist handling improvements Bart Van Assche
2017-12-04 18:36 ` [PATCH 1/3] scsi_get_device_flags_keyed(): Always return device flags Bart Van Assche
2017-12-04 18:36 ` [PATCH 2/3] Use blist_flags_t consistently Bart Van Assche
2017-12-04 18:36 ` [PATCH 3/3] Introduce scsi_devinfo_key enumeration type Bart Van Assche
2017-12-07 2:03 ` [PATCH 0/3] SCSI device blacklist handling improvements Martin K. Petersen
2017-12-07 17:34 ` Bart Van Assche
2017-12-08 1:10 ` Martin K. Petersen
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).