diff mbox

[11/16] bcache: Check the d->disk pointer before using it

Message ID 20180315150814.9412-12-bart.vanassche@wdc.com (mailing list archive)
State New, archived
Headers show

Commit Message

Bart Van Assche March 15, 2018, 3:08 p.m. UTC
Since bcache_device_free() checks the d->disk pointer I think that
means that that pointer can be NULL. Hence test that pointer before
using it. This was detected by smatch.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
---
 drivers/md/bcache/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Coly Li March 15, 2018, 4:25 p.m. UTC | #1
On 15/03/2018 11:08 PM, Bart Van Assche wrote:
> Since bcache_device_free() checks the d->disk pointer I think that
> means that that pointer can be NULL. Hence test that pointer before
> using it. This was detected by smatch.
> 
> Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>

Reviewed-by: Coly Li <colyli@suse.de>

Thanks.

Coly Li

> ---
>  drivers/md/bcache/super.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> index d19a44cd1fd7..39bec137f636 100644
> --- a/drivers/md/bcache/super.c
> +++ b/drivers/md/bcache/super.c
> @@ -742,7 +742,7 @@ static void bcache_device_free(struct bcache_device *d)
>  {
>  	lockdep_assert_held(&bch_register_lock);
>  
> -	pr_info("%s stopped", d->disk->disk_name);
> +	pr_info("%s stopped", d->disk ? d->disk->disk_name : "(?)");
>  
>  	if (d->c)
>  		bcache_device_detach(d);
>
diff mbox

Patch

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index d19a44cd1fd7..39bec137f636 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -742,7 +742,7 @@  static void bcache_device_free(struct bcache_device *d)
 {
 	lockdep_assert_held(&bch_register_lock);
 
-	pr_info("%s stopped", d->disk->disk_name);
+	pr_info("%s stopped", d->disk ? d->disk->disk_name : "(?)");
 
 	if (d->c)
 		bcache_device_detach(d);