public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Qing Wang <wangqing@vivo.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] block: return specific error when pointer is NULL
Date: Thu, 23 Dec 2021 00:57:31 -0800	[thread overview]
Message-ID: <YcQ5+76XpcbcsotJ@infradead.org> (raw)
In-Reply-To: <1640226246-32691-1-git-send-email-wangqing@vivo.com>

On Wed, Dec 22, 2021 at 06:24:03PM -0800, Qing Wang wrote:
> From: Wang Qing <wangqing@vivo.com>
> 
> loop_attr_backing_file_show() better return specific error than 0 
> when pointer is NULL

Well, let's turn this into something that is not butt ugly then:

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 7f4ea06534c2d..b9ee0a165b75e 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -666,15 +666,15 @@ static ssize_t loop_attr_backing_file_show(struct loop_device *lo, char *buf)
 		p = file_path(lo->lo_backing_file, buf, PAGE_SIZE - 1);
 	spin_unlock_irq(&lo->lo_lock);
 
-	if (IS_ERR_OR_NULL(p))
-		ret = PTR_ERR(p);
-	else {
-		ret = strlen(p);
-		memmove(buf, p, ret);
-		buf[ret++] = '\n';
-		buf[ret] = 0;
-	}
-
+	if (!p)
+		return -ENOENT;
+	if (IS_ERR(p))
+		return PTR_ERR(p);
+
+	ret = strlen(p);
+	memmove(buf, p, ret);
+	buf[ret++] = '\n';
+	buf[ret] = 0;
 	return ret;
 }
 

      reply	other threads:[~2021-12-23  8:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-23  2:24 [PATCH] block: return specific error when pointer is NULL Qing Wang
2021-12-23  8:57 ` Christoph Hellwig [this message]

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=YcQ5+76XpcbcsotJ@infradead.org \
    --to=hch@infradead.org \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wangqing@vivo.com \
    /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