Skip to contentSkip to conversation

xen/xenbus: handle pointer to NULL in alloc/free_pdev

PATCH NAK [email protected] 2 participants 2 messages May 29, 2024 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/xenbus: handle pointer to NULL in alloc/free_pdev

From: Yunseong Kim <[email protected]>

Modify 'alloc_pdev()' to set 'pdev->xdev' to NULL
if 'xen_pcibk_init_devices()' fails. This ensures that 'pdev->xdev' does not point to 'xdev' when 'pdev' is freed.
And modify 'free_pdev()' to set 'pdev' to NULL.

---
 drivers/xen/xen-pciback/xenbus.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/xen/xen-pciback/xenbus.c +2 -0
index b11e401f1b1e..f1709b8e284a 100644
@@ -54,6 +54,7 @@ static struct xen_pcibk_device *alloc_pdev(struct xenbus_device *xdev)
 	INIT_WORK(&pdev->op_work, xen_pcibk_do_op);
 
 	if (xen_pcibk_init_devices(pdev)) {
+		pdev->xdev = NULL;
 		kfree(pdev);
 		pdev = NULL;
 	}
@@ -102,6 +103,7 @@ static void free_pdev(struct xen_pcibk_device *pdev)
 	pdev->xdev = NULL;
 
 	kfree(pdev);
+	pdev = NULL;
 }
 
 static int xen_pcibk_do_attach(struct xen_pcibk_device *pdev, int gnt_ref,
Signature · 1 line
2.34.1
maintainer NAK
#1 lore raw
Quoted 25 lines · On 29.05.24 15:19, [email protected] wrote:

From: Yunseong Kim <[email protected]>

Modify 'alloc_pdev()' to set 'pdev->xdev' to NULL
if 'xen_pcibk_init_devices()' fails. This ensures that 'pdev->xdev' does not point to 'xdev' when 'pdev' is freed.
And modify 'free_pdev()' to set 'pdev' to NULL.

---
  drivers/xen/xen-pciback/xenbus.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/xen/xen-pciback/xenbus.c +1 -0
index b11e401f1b1e..f1709b8e284a 100644
@@ -54,6 +54,7 @@ static struct xen_pcibk_device *alloc_pdev(struct xenbus_device *xdev)
  	INIT_WORK(&pdev->op_work, xen_pcibk_do_op);
 
  	if (xen_pcibk_init_devices(pdev)) {
+		pdev->xdev = NULL;
  		kfree(pdev);
  		pdev = NULL;
  	}

drivers/xen/xen-pciback/xenbus.c static void free_pdev(struct xen_pcibk_device *pdev) · line 109

Quoted 7 lines
drivers/xen/xen-pciback/xenbus.c +1 -0
@@ -102,6 +103,7 @@ static void free_pdev(struct xen_pcibk_device *pdev)
  	pdev->xdev = NULL;
 
  	kfree(pdev);
+	pdev = NULL;
  }
 
  static int xen_pcibk_do_attach(struct xen_pcibk_device *pdev, int gnt_ref,

NAK!

Please stop that nonsense. NULL-ing pointers which have no chance to be used any more is just adding code for no purpose at all.

Please don't send other iterations of this patch. You are wasting review bandwidth.

Juergen