Re: [PATCH] block: return specific error when pointer is NULL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Dec 22, 2021 at 06:24:03PM -0800, Qing Wang wrote:
> From: Wang Qing <wangqing@xxxxxxxx>
> 
> 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;
 }
 



[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux