mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Yeqi Fu <asuk4.q@gmail.com>,
	ulf.hansson@linaro.org, CLoehle@hyperstone.com,
	avri.altman@wdc.com, axboe@kernel.dk
Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ivan Orlov <ivan.orlov0322@gmail.com>
Subject: Re: [PATCH] mmc: core: Fix error checking
Date: Thu, 18 May 2023 11:15:31 +0300	[thread overview]
Message-ID: <36e805fa-338d-a945-2621-75c5077572fc@intel.com> (raw)
In-Reply-To: <20230517192654.367892-1-asuk4.q@gmail.com>

On 17/05/23 22:26, Yeqi Fu wrote:
> The functions debugfs_create_dir and debugfs_create_file_unsafe return
> ERR_PTR if an error occurs, and the appropriate way to verify for errors
> is to use the inline function IS_ERR. The patch will substitute the
> null-comparison with IS_ERR.
> 
> Suggested-by: Ivan Orlov <ivan.orlov0322@gmail.com>
> Signed-off-by: Yeqi Fu <asuk4.q@gmail.com>
> ---
>  drivers/mmc/core/block.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
> index 00c33edb9fb9..507bebc22636 100644
> --- a/drivers/mmc/core/block.c
> +++ b/drivers/mmc/core/block.c
> @@ -2908,7 +2908,7 @@ static int mmc_blk_add_debugfs(struct mmc_card *card, struct mmc_blk_data *md)
>  			debugfs_create_file_unsafe("status", 0400, root,
>  						   card,
>  						   &mmc_dbg_card_status_fops);
> -		if (!md->status_dentry)
> +		if (IS_ERR(md->status_dentry))
>  			return -EIO;
>  	}
>  
> @@ -2916,7 +2916,7 @@ static int mmc_blk_add_debugfs(struct mmc_card *card, struct mmc_blk_data *md)
>  		md->ext_csd_dentry =
>  			debugfs_create_file("ext_csd", S_IRUSR, root, card,
>  					    &mmc_dbg_ext_csd_fops);
> -		if (!md->ext_csd_dentry)
> +		if (IS_ERR(md->ext_csd_dentry))
>  			return -EIO;
>  	}
>  

The patch is not wrong, but you also need to look at the bigger picture.
In this case, the return value is not used.  And debugfs API is designed
so that return values can be ignored - for example, it is ok to pass NULL
or an error code to debugfs_remove().  Generally we don't care if debugfs
fails, because it is only for debugging, but it only uses memory resources
so it essentially doesn't fail anyway - except when it is not compiled in.

So you could change mmc_blk_add_debugfs() to return void, and drop the error
checks entirely.

The error checks in mmc_blk_remove_debugfs() also serve no purpose.


  reply	other threads:[~2023-05-18  8:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-17 19:26 Yeqi Fu
2023-05-18  8:15 ` Adrian Hunter [this message]
2023-05-18 10:12   ` [PATCH] mmc: core: Remove unnecessary error checks and change return type Yeqi Fu
2023-05-18 16:43     ` Adrian Hunter
2023-05-24 13:10     ` Ulf Hansson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=36e805fa-338d-a945-2621-75c5077572fc@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=CLoehle@hyperstone.com \
    --cc=asuk4.q@gmail.com \
    --cc=avri.altman@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=ivan.orlov0322@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®