Skip to contentSkip to conversation

md/md-linear: Fix a NULL vs IS_ERR() bug in linear_add()

PATCH In review Dan Carpenter 2 participants 2 messages Jan 15, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 md/md-linear: Fix a NULL vs IS_ERR() bug in linear_add()

The linear_conf() returns error pointers, it doesn't return NULL. Update the error checking to match.

Fixes 127186cfb184 ("md: reintroduce md-linear")
---
 drivers/md/md-linear.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/md-linear.c +2 -2
index 53bc3fda9edb..a382929ce7ba 100644
@@ -204,8 +204,8 @@ static int linear_add(struct mddev *mddev, struct md_rdev *rdev)
 	rdev->saved_raid_disk = -1;
 
 	newconf = linear_conf(mddev, mddev->raid_disks + 1);
-	if (!newconf)
-		return -ENOMEM;
+	if (IS_ERR(newconf))
+		return PTR_ERR(newconf);
 
 	/* newconf->raid_disks already keeps a copy of * the increased
 	 * value of mddev->raid_disks, WARN_ONCE() is just used to make
Signature · 1 line
2.45.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Dan Carpenter

The linear_conf() returns error pointers, it doesn't return NULL. Update the error checking to match.

Fixes 127186cfb184 ("md: reintroduce md-linear")
---
  drivers/md/md-linear.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

LGTM

Quoted 16 lines
drivers/md/md-linear.c +2 -2
index 53bc3fda9edb..a382929ce7ba 100644
@@ -204,8 +204,8 @@ static int linear_add(struct mddev *mddev, struct md_rdev *rdev)
  	rdev->saved_raid_disk = -1;
 
  	newconf = linear_conf(mddev, mddev->raid_disks + 1);
-	if (!newconf)
-		return -ENOMEM;
+	if (IS_ERR(newconf))
+		return PTR_ERR(newconf);
 
  	/* newconf->raid_disks already keeps a copy of * the increased
  	 * value of mddev->raid_disks, WARN_ONCE() is just used to make