diff mbox series

block: remove more NULL checks after bdev_get_queue()

Message ID 20230202091151.855784-1-qkrwngud825@gmail.com (mailing list archive)
State New, archived
Headers show
Series block: remove more NULL checks after bdev_get_queue() | expand

Commit Message

Juhyung Park Feb. 2, 2023, 9:11 a.m. UTC
bdev_get_queue() never returns NULL. Several commits [1][2] have been made
before to remove such superfluous checks, but some still remained.

[1] commit ec9fd2a13d74 ("blk-lib: don't check bdev_get_queue() NULL check")
[2] commit fea127b36c93 ("block: remove superfluous check for request queue in bdev_is_zoned()")

Signed-off-by: Juhyung Park <qkrwngud825@gmail.com>
---
 block/blk-zoned.c       | 4 ----
 include/linux/blkdev.h  | 7 +------
 kernel/trace/blktrace.c | 6 +-----
 3 files changed, 2 insertions(+), 15 deletions(-)

Comments

Johannes Thumshirn Feb. 2, 2023, 9:33 a.m. UTC | #1
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Pankaj Raghav Feb. 2, 2023, 11:56 a.m. UTC | #2
On Thu, Feb 02, 2023 at 06:11:51PM +0900, Juhyung Park wrote:
> bdev_get_queue() never returns NULL. Several commits [1][2] have been made
> before to remove such superfluous checks, but some still remained.
> 
> [1] commit ec9fd2a13d74 ("blk-lib: don't check bdev_get_queue() NULL check")
> [2] commit fea127b36c93 ("block: remove superfluous check for request queue in bdev_is_zoned()")
> 
> Signed-off-by: Juhyung Park <qkrwngud825@gmail.com>

Looks good,
Reviewed-by: Pankaj Raghav <p.raghav@samsung.com>
Chaitanya Kulkarni Feb. 2, 2023, 5:42 p.m. UTC | #3
On 2/2/23 01:11, Juhyung Park wrote:
> bdev_get_queue() never returns NULL. Several commits [1][2] have been made
> before to remove such superfluous checks, but some still remained.
> 
> [1] commit ec9fd2a13d74 ("blk-lib: don't check bdev_get_queue() NULL check")
> [2] commit fea127b36c93 ("block: remove superfluous check for request queue in bdev_is_zoned()")
> 
> Signed-off-by: Juhyung Park <qkrwngud825@gmail.com>

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck
kernel test robot Feb. 3, 2023, 12:04 a.m. UTC | #4
Hi Juhyung,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on axboe-block/for-next]
[also build test WARNING on linus/master v6.2-rc6 next-20230202]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Juhyung-Park/block-remove-more-NULL-checks-after-bdev_get_queue/20230202-171443
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
patch link:    https://lore.kernel.org/r/20230202091151.855784-1-qkrwngud825%40gmail.com
patch subject: [PATCH] block: remove more NULL checks after bdev_get_queue()
config: x86_64-rhel-8.3-func (https://download.01.org/0day-ci/archive/20230203/202302030733.TVNhMvP4-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/f62253701c6bf771227300ca8c572c778c2670bb
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Juhyung-Park/block-remove-more-NULL-checks-after-bdev_get_queue/20230202-171443
        git checkout f62253701c6bf771227300ca8c572c778c2670bb
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=x86_64 olddefconfig
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   block/blk-zoned.c: In function 'blkdev_report_zones_ioctl':
>> block/blk-zoned.c:337:31: warning: variable 'q' set but not used [-Wunused-but-set-variable]
     337 |         struct request_queue *q;
         |                               ^
   block/blk-zoned.c: In function 'blkdev_zone_mgmt_ioctl':
   block/blk-zoned.c:392:31: warning: variable 'q' set but not used [-Wunused-but-set-variable]
     392 |         struct request_queue *q;
         |                               ^


vim +/q +337 block/blk-zoned.c

d41003513e61dd Christoph Hellwig 2019-11-11  327  
56c4bddb970658 Bart Van Assche   2018-03-08  328  /*
3ed05a987e0f63 Shaun Tancheff    2016-10-18  329   * BLKREPORTZONE ioctl processing.
3ed05a987e0f63 Shaun Tancheff    2016-10-18  330   * Called from blkdev_ioctl.
3ed05a987e0f63 Shaun Tancheff    2016-10-18  331   */
3ed05a987e0f63 Shaun Tancheff    2016-10-18  332  int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode,
3ed05a987e0f63 Shaun Tancheff    2016-10-18  333  			      unsigned int cmd, unsigned long arg)
3ed05a987e0f63 Shaun Tancheff    2016-10-18  334  {
3ed05a987e0f63 Shaun Tancheff    2016-10-18  335  	void __user *argp = (void __user *)arg;
d41003513e61dd Christoph Hellwig 2019-11-11  336  	struct zone_report_args args;
3ed05a987e0f63 Shaun Tancheff    2016-10-18 @337  	struct request_queue *q;
3ed05a987e0f63 Shaun Tancheff    2016-10-18  338  	struct blk_zone_report rep;
3ed05a987e0f63 Shaun Tancheff    2016-10-18  339  	int ret;
3ed05a987e0f63 Shaun Tancheff    2016-10-18  340  
3ed05a987e0f63 Shaun Tancheff    2016-10-18  341  	if (!argp)
3ed05a987e0f63 Shaun Tancheff    2016-10-18  342  		return -EINVAL;
3ed05a987e0f63 Shaun Tancheff    2016-10-18  343  
3ed05a987e0f63 Shaun Tancheff    2016-10-18  344  	q = bdev_get_queue(bdev);
3ed05a987e0f63 Shaun Tancheff    2016-10-18  345  
edd1dbc83b1de3 Christoph Hellwig 2022-07-06  346  	if (!bdev_is_zoned(bdev))
3ed05a987e0f63 Shaun Tancheff    2016-10-18  347  		return -ENOTTY;
3ed05a987e0f63 Shaun Tancheff    2016-10-18  348  
3ed05a987e0f63 Shaun Tancheff    2016-10-18  349  	if (copy_from_user(&rep, argp, sizeof(struct blk_zone_report)))
3ed05a987e0f63 Shaun Tancheff    2016-10-18  350  		return -EFAULT;
3ed05a987e0f63 Shaun Tancheff    2016-10-18  351  
3ed05a987e0f63 Shaun Tancheff    2016-10-18  352  	if (!rep.nr_zones)
3ed05a987e0f63 Shaun Tancheff    2016-10-18  353  		return -EINVAL;
3ed05a987e0f63 Shaun Tancheff    2016-10-18  354  
d41003513e61dd Christoph Hellwig 2019-11-11  355  	args.zones = argp + sizeof(struct blk_zone_report);
d41003513e61dd Christoph Hellwig 2019-11-11  356  	ret = blkdev_report_zones(bdev, rep.sector, rep.nr_zones,
d41003513e61dd Christoph Hellwig 2019-11-11  357  				  blkdev_copy_zone_to_user, &args);
d41003513e61dd Christoph Hellwig 2019-11-11  358  	if (ret < 0)
3ed05a987e0f63 Shaun Tancheff    2016-10-18  359  		return ret;
d41003513e61dd Christoph Hellwig 2019-11-11  360  
d41003513e61dd Christoph Hellwig 2019-11-11  361  	rep.nr_zones = ret;
82394db7383d33 Matias Bjørling   2020-06-29  362  	rep.flags = BLK_ZONE_REP_CAPACITY;
d41003513e61dd Christoph Hellwig 2019-11-11  363  	if (copy_to_user(argp, &rep, sizeof(struct blk_zone_report)))
d41003513e61dd Christoph Hellwig 2019-11-11  364  		return -EFAULT;
d41003513e61dd Christoph Hellwig 2019-11-11  365  	return 0;
3ed05a987e0f63 Shaun Tancheff    2016-10-18  366  }
3ed05a987e0f63 Shaun Tancheff    2016-10-18  367
Juhyung Park Feb. 3, 2023, 2:45 a.m. UTC | #5
Welp, didn't have it build-tested with W=1 and it somehow didn't warn
me without it.

Just posted v2:
https://lore.kernel.org/all/20230203024029.48260-1-qkrwngud825@gmail.com/T/#u

Sorry for the inconvenience!
Thanks,

On Fri, Feb 3, 2023 at 9:05 AM kernel test robot <lkp@intel.com> wrote:
>
> Hi Juhyung,
>
> Thank you for the patch! Perhaps something to improve:
>
> [auto build test WARNING on axboe-block/for-next]
> [also build test WARNING on linus/master v6.2-rc6 next-20230202]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
>
> url:    https://github.com/intel-lab-lkp/linux/commits/Juhyung-Park/block-remove-more-NULL-checks-after-bdev_get_queue/20230202-171443
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
> patch link:    https://lore.kernel.org/r/20230202091151.855784-1-qkrwngud825%40gmail.com
> patch subject: [PATCH] block: remove more NULL checks after bdev_get_queue()
> config: x86_64-rhel-8.3-func (https://download.01.org/0day-ci/archive/20230203/202302030733.TVNhMvP4-lkp@intel.com/config)
> compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
> reproduce (this is a W=1 build):
>         # https://github.com/intel-lab-lkp/linux/commit/f62253701c6bf771227300ca8c572c778c2670bb
>         git remote add linux-review https://github.com/intel-lab-lkp/linux
>         git fetch --no-tags linux-review Juhyung-Park/block-remove-more-NULL-checks-after-bdev_get_queue/20230202-171443
>         git checkout f62253701c6bf771227300ca8c572c778c2670bb
>         # save the config file
>         mkdir build_dir && cp config build_dir/.config
>         make W=1 O=build_dir ARCH=x86_64 olddefconfig
>         make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
>
> If you fix the issue, kindly add following tag where applicable
> | Reported-by: kernel test robot <lkp@intel.com>
>
> All warnings (new ones prefixed by >>):
>
>    block/blk-zoned.c: In function 'blkdev_report_zones_ioctl':
> >> block/blk-zoned.c:337:31: warning: variable 'q' set but not used [-Wunused-but-set-variable]
>      337 |         struct request_queue *q;
>          |                               ^
>    block/blk-zoned.c: In function 'blkdev_zone_mgmt_ioctl':
>    block/blk-zoned.c:392:31: warning: variable 'q' set but not used [-Wunused-but-set-variable]
>      392 |         struct request_queue *q;
>          |                               ^
>
>
> vim +/q +337 block/blk-zoned.c
>
> d41003513e61dd Christoph Hellwig 2019-11-11  327
> 56c4bddb970658 Bart Van Assche   2018-03-08  328  /*
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  329   * BLKREPORTZONE ioctl processing.
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  330   * Called from blkdev_ioctl.
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  331   */
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  332  int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode,
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  333                              unsigned int cmd, unsigned long arg)
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  334  {
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  335        void __user *argp = (void __user *)arg;
> d41003513e61dd Christoph Hellwig 2019-11-11  336        struct zone_report_args args;
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18 @337        struct request_queue *q;
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  338        struct blk_zone_report rep;
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  339        int ret;
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  340
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  341        if (!argp)
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  342                return -EINVAL;
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  343
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  344        q = bdev_get_queue(bdev);
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  345
> edd1dbc83b1de3 Christoph Hellwig 2022-07-06  346        if (!bdev_is_zoned(bdev))
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  347                return -ENOTTY;
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  348
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  349        if (copy_from_user(&rep, argp, sizeof(struct blk_zone_report)))
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  350                return -EFAULT;
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  351
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  352        if (!rep.nr_zones)
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  353                return -EINVAL;
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  354
> d41003513e61dd Christoph Hellwig 2019-11-11  355        args.zones = argp + sizeof(struct blk_zone_report);
> d41003513e61dd Christoph Hellwig 2019-11-11  356        ret = blkdev_report_zones(bdev, rep.sector, rep.nr_zones,
> d41003513e61dd Christoph Hellwig 2019-11-11  357                                  blkdev_copy_zone_to_user, &args);
> d41003513e61dd Christoph Hellwig 2019-11-11  358        if (ret < 0)
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  359                return ret;
> d41003513e61dd Christoph Hellwig 2019-11-11  360
> d41003513e61dd Christoph Hellwig 2019-11-11  361        rep.nr_zones = ret;
> 82394db7383d33 Matias Bjørling   2020-06-29  362        rep.flags = BLK_ZONE_REP_CAPACITY;
> d41003513e61dd Christoph Hellwig 2019-11-11  363        if (copy_to_user(argp, &rep, sizeof(struct blk_zone_report)))
> d41003513e61dd Christoph Hellwig 2019-11-11  364                return -EFAULT;
> d41003513e61dd Christoph Hellwig 2019-11-11  365        return 0;
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  366  }
> 3ed05a987e0f63 Shaun Tancheff    2016-10-18  367
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests
diff mbox series

Patch

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 614b575be899..40a3e59fb8e0 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -342,8 +342,6 @@  int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode,
 		return -EINVAL;
 
 	q = bdev_get_queue(bdev);
-	if (!q)
-		return -ENXIO;
 
 	if (!bdev_is_zoned(bdev))
 		return -ENOTTY;
@@ -400,8 +398,6 @@  int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode,
 		return -EINVAL;
 
 	q = bdev_get_queue(bdev);
-	if (!q)
-		return -ENXIO;
 
 	if (!bdev_is_zoned(bdev))
 		return -ENOTTY;
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index b9637d63e6f0..89dd9b02b45b 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1276,12 +1276,7 @@  static inline bool bdev_nowait(struct block_device *bdev)
 
 static inline enum blk_zoned_model bdev_zoned_model(struct block_device *bdev)
 {
-	struct request_queue *q = bdev_get_queue(bdev);
-
-	if (q)
-		return blk_queue_zoned_model(q);
-
-	return BLK_ZONED_NONE;
+	return blk_queue_zoned_model(bdev_get_queue(bdev));
 }
 
 static inline bool bdev_is_zoned(struct block_device *bdev)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 918a7d12df8f..e5e8963d6808 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -729,14 +729,10 @@  EXPORT_SYMBOL_GPL(blk_trace_startstop);
  **/
 int blk_trace_ioctl(struct block_device *bdev, unsigned cmd, char __user *arg)
 {
-	struct request_queue *q;
+	struct request_queue *q = bdev_get_queue(bdev);
 	int ret, start = 0;
 	char b[BDEVNAME_SIZE];
 
-	q = bdev_get_queue(bdev);
-	if (!q)
-		return -ENXIO;
-
 	mutex_lock(&q->debugfs_mutex);
 
 	switch (cmd) {