Message ID | 1502348731-63534-3-git-send-email-hare@suse.de (mailing list archive) |
---|---|
State | Changes Requested, archived |
Headers | show |
switch()es are so much nicer to read :-)
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
On Thu, Aug 10, 2017 at 09:05:30AM +0200, Hannes Reinecke wrote: > Rework scsi_internal_device_unblock_nowait() into using a > switch statement. > No functional changes. > > Signed-off-by: Hannes Reinecke <hare@suse.com> > --- > drivers/scsi/scsi_lib.c | 18 ++++++++++++------ > 1 file changed, 12 insertions(+), 6 deletions(-) > > diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c > index 1ae531b..035aa4c 100644 > --- a/drivers/scsi/scsi_lib.c > +++ b/drivers/scsi/scsi_lib.c > @@ -3074,19 +3074,25 @@ int scsi_internal_device_unblock_nowait(struct scsi_device *sdev, > * Try to transition the scsi device to SDEV_RUNNING or one of the > * offlined states and goose the device queue if successful. > */ > - if ((sdev->sdev_state == SDEV_BLOCK) || > - (sdev->sdev_state == SDEV_TRANSPORT_OFFLINE)) > + switch (sdev->sdev_state) { > + case SDEV_BLOCK: > + case SDEV_TRANSPORT_OFFLINE: > sdev->sdev_state = new_state; > - else if (sdev->sdev_state == SDEV_CREATED_BLOCK) { > + break; > + case SDEV_CREATED_BLOCK: > if (new_state == SDEV_TRANSPORT_OFFLINE || > new_state == SDEV_OFFLINE) > sdev->sdev_state = new_state; > else > sdev->sdev_state = SDEV_CREATED; > - } else if (sdev->sdev_state != SDEV_CANCEL && > - sdev->sdev_state != SDEV_OFFLINE) > + break; > + case SDEV_TRANSPORT_OFFLINE: > + case SDEV_CANCEL: > + case SDEV_OFFLINE: > + break; > + default: > return -EINVAL; This changes ok by default to reject by default and instead lists the ok states. Which probably is the right thing to do for future proofing against new states, so: Reviewed-by: Christoph Hellwig <hch@lst.de>
Hi Hannes, [auto build test ERROR on mkp-scsi/for-next] [also build test ERROR on v4.13-rc4 next-20170810] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] url: https://github.com/0day-ci/linux/commits/Hannes-Reinecke/scsi-pollable-state-attribute/20170811-071630 base: https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next config: xtensa-allmodconfig (attached as .config) compiler: xtensa-linux-gcc (GCC) 4.9.0 reproduce: wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross ARCH=xtensa All errors (new ones prefixed by >>): drivers/scsi/scsi_lib.c: In function 'scsi_internal_device_unblock_nowait': >> drivers/scsi/scsi_lib.c:3089:2: error: duplicate case value case SDEV_TRANSPORT_OFFLINE: ^ >> drivers/scsi/scsi_lib.c:3079:2: error: previously used here case SDEV_TRANSPORT_OFFLINE: ^ vim +3089 drivers/scsi/scsi_lib.c 3054 3055 /** 3056 * scsi_internal_device_unblock_nowait - resume a device after a block request 3057 * @sdev: device to resume 3058 * @new_state: state to set the device to after unblocking 3059 * 3060 * Restart the device queue for a previously suspended SCSI device. Does not 3061 * sleep. 3062 * 3063 * Returns zero if successful or a negative error code upon failure. 3064 * 3065 * Notes: 3066 * This routine transitions the device to the SDEV_RUNNING state or to one of 3067 * the offline states (which must be a legal transition) allowing the midlayer 3068 * to goose the queue for this device. 3069 */ 3070 int scsi_internal_device_unblock_nowait(struct scsi_device *sdev, 3071 enum scsi_device_state new_state) 3072 { 3073 /* 3074 * Try to transition the scsi device to SDEV_RUNNING or one of the 3075 * offlined states and goose the device queue if successful. 3076 */ 3077 switch (sdev->sdev_state) { 3078 case SDEV_BLOCK: > 3079 case SDEV_TRANSPORT_OFFLINE: 3080 sdev->sdev_state = new_state; 3081 break; 3082 case SDEV_CREATED_BLOCK: 3083 if (new_state == SDEV_TRANSPORT_OFFLINE || 3084 new_state == SDEV_OFFLINE) 3085 sdev->sdev_state = new_state; 3086 else 3087 sdev->sdev_state = SDEV_CREATED; 3088 break; > 3089 case SDEV_TRANSPORT_OFFLINE: 3090 case SDEV_CANCEL: 3091 case SDEV_OFFLINE: 3092 break; 3093 default: 3094 return -EINVAL; 3095 } 3096 scsi_start_queue(sdev); 3097 3098 return 0; 3099 } 3100 EXPORT_SYMBOL_GPL(scsi_internal_device_unblock_nowait); 3101 --- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 1ae531b..035aa4c 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -3074,19 +3074,25 @@ int scsi_internal_device_unblock_nowait(struct scsi_device *sdev, * Try to transition the scsi device to SDEV_RUNNING or one of the * offlined states and goose the device queue if successful. */ - if ((sdev->sdev_state == SDEV_BLOCK) || - (sdev->sdev_state == SDEV_TRANSPORT_OFFLINE)) + switch (sdev->sdev_state) { + case SDEV_BLOCK: + case SDEV_TRANSPORT_OFFLINE: sdev->sdev_state = new_state; - else if (sdev->sdev_state == SDEV_CREATED_BLOCK) { + break; + case SDEV_CREATED_BLOCK: if (new_state == SDEV_TRANSPORT_OFFLINE || new_state == SDEV_OFFLINE) sdev->sdev_state = new_state; else sdev->sdev_state = SDEV_CREATED; - } else if (sdev->sdev_state != SDEV_CANCEL && - sdev->sdev_state != SDEV_OFFLINE) + break; + case SDEV_TRANSPORT_OFFLINE: + case SDEV_CANCEL: + case SDEV_OFFLINE: + break; + default: return -EINVAL; - + } scsi_start_queue(sdev); return 0;
Rework scsi_internal_device_unblock_nowait() into using a switch statement. No functional changes. Signed-off-by: Hannes Reinecke <hare@suse.com> --- drivers/scsi/scsi_lib.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)