Skip to contentSkip to conversation

vfio/mdev: remove unnecessary NULL check in mbochs_create()

PATCH Superseded Dan Carpenter 3 participants 3 messages Apr 21, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfio/mdev: remove unnecessary NULL check in mbochs_create()

This NULL check is no longer required because "type" now points to an element in a non-NULL array.

Fixes 3d3a360e570616 ("vfio/mbochs: Use mdev_get_type_group_id()")
---
 samples/vfio-mdev/mbochs.c | 2 --
 samples/vfio-mdev/mdpy.c | 3 +--
 2 files changed, 1 insertion(+), 4 deletions(-)
samples/vfio-mdev/mbochs.c +0 -2
index 861c76914e76..881ef9a7296f 100644
@@ -513,8 +513,6 @@ static int mbochs_create(struct mdev_device *mdev)
 	struct device *dev = mdev_dev(mdev);
 	struct mdev_state *mdev_state;
 
-	if (!type)
-		type = &mbochs_types[0];
 	if (type->mbytes + mbochs_used_mbytes > max_mbytes)
 		return -ENOMEM;
 
samples/vfio-mdev/mdpy.c +1 -2
index f0c0e7209719..e889c1cf8fd1 100644
@@ -667,8 +667,7 @@ static ssize_t description_show(struct mdev_type *mtype,
 		&mdpy_types[mtype_get_type_group_id(mtype)];
 
 	return sprintf(buf, "virtual display, %dx%d framebuffer\n",
-		       type ? type->width  : 0,
-		       type ? type->height : 0);
+		       type->width, type->height);
 }
 static MDEV_TYPE_ATTR_RO(description);
 
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Dan Carpenter

This NULL check is no longer required because "type" now points to an element in a non-NULL array.

Fixes 3d3a360e570616 ("vfio/mbochs: Use mdev_get_type_group_id()")
---
 samples/vfio-mdev/mbochs.c | 2 --
 samples/vfio-mdev/mdpy.c | 3 +--
 2 files changed, 1 insertion(+), 4 deletions(-)

Thanks,
Jason

#2 lore raw
In reply to Dan Carpenter
Quoted 2 lines · On Wed, 21 Apr 2021 16:29:36 +0300 Dan Carpenter <[email protected]>…

This NULL check is no longer required because "type" now points to an element in a non-NULL array.

I think the mdpy change is correct too, but it's hard to verify from this commit log that it was actually intended. Can we note that change as well? Thanks,

Alex

Quoted 35 lines
Fixes 3d3a360e570616 ("vfio/mbochs: Use mdev_get_type_group_id()")
---
 samples/vfio-mdev/mbochs.c | 2 --
 samples/vfio-mdev/mdpy.c | 3 +--
 2 files changed, 1 insertion(+), 4 deletions(-)
samples/vfio-mdev/mbochs.c +0 -2
index 861c76914e76..881ef9a7296f 100644
@@ -513,8 +513,6 @@ static int mbochs_create(struct mdev_device *mdev)
 	struct device *dev = mdev_dev(mdev);
 	struct mdev_state *mdev_state;
 
-	if (!type)
-		type = &mbochs_types[0];
 	if (type->mbytes + mbochs_used_mbytes > max_mbytes)
 		return -ENOMEM;
 
samples/vfio-mdev/mdpy.c +1 -2
index f0c0e7209719..e889c1cf8fd1 100644
@@ -667,8 +667,7 @@ static ssize_t description_show(struct mdev_type *mtype,
 		&mdpy_types[mtype_get_type_group_id(mtype)];
 
 	return sprintf(buf, "virtual display, %dx%d framebuffer\n",
-		       type ? type->width  : 0,
-		       type ? type->height : 0);
+		       type->width, type->height);
 }
 static MDEV_TYPE_ATTR_RO(description);