Skip to contentSkip to conversation

block: return specific error when pointer is NULL

PATCH In review Qing Wang 2 participants 2 messages Dec 23, 2021 Block layer

lore
Share & tools
lore

Qing Wang

author
#0 lore raw

PATCH 1/1 block: return specific error when pointer is NULL

From: Wang Qing <[email protected]>

loop_attr_backing_file_show() better return specific error than 0 when pointer is NULL

---
 drivers/block/loop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/loop.c +1 -1
index e52a8a5..860a5b6
@@ -667,7 +667,7 @@ static ssize_t loop_attr_backing_file_show(struct loop_device *lo, char *buf)
 	spin_unlock_irq(&lo->lo_lock);
 
 	if (IS_ERR_OR_NULL(p))
-		ret = PTR_ERR(p);
+		ret = p ? PTR_ERR(p) : -ENOENT;
 	else {
 		ret = strlen(p);
 		memmove(buf, p, ret);
Signature · 1 line
2.7.4
#1 lore raw
Quoted 4 lines · Qing Wang

From: Wang Qing <[email protected]>

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:

drivers/block/loop.c +9 -9
index 7f4ea06534c2d..b9ee0a165b75e 100644
@@ -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;
 }