Skip to contentSkip to conversation

xen: check return value of xenbus_printf

PATCH In review Insu Yun 2 participants 2 messages Oct 19, 2015

Subsystems (2)
lore
Share & tools
lore

Insu Yun

author
#0 lore raw

PATCH 1/1 xen: check return value of xenbus_printf

Internally, xenbus_printf uses memory allocation, so it can be failed in memory pressure.Therefore, xenbus_printf's return should be checked and properly handled.

---
 drivers/input/misc/xen-kbdfront.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/input/misc/xen-kbdfront.c +8 -2
index 23d0549..9d465d7 100644
@@ -129,8 +129,14 @@ static int xenkbd_probe(struct xenbus_device *dev,
 
 	if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-abs-pointer", "%d", &abs) < 0)
 		abs = 0;
-	if (abs)
-		xenbus_printf(XBT_NIL, dev->nodename, "request-abs-pointer", "1");
+	if (abs) {
+		ret = xenbus_printf(XBT_NIL, dev->nodename,
+					"request-abs-pointer", "1");
+		if (ret) {
+			pr_warning("xenkbd: can't request abs-pointer");
+			abs = 0;
+		}
+	}
 
 	/* keyboard */
 	kbd = input_allocate_device();
Signature · 1 line
1.9.1
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 14 lines · Insu Yun

Internally, xenbus_printf uses memory allocation, so it can be failed in memory pressure.Therefore, xenbus_printf's return should be checked and properly handled.

---
 drivers/input/misc/xen-kbdfront.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/input/misc/xen-kbdfront.c +0 -0
index 23d0549..9d465d7 100644

drivers/input/misc/xen-kbdfront.c static int xenkbd_probe(struct xenbus_device *dev, · line 134

Quoted 8 lines
drivers/input/misc/xen-kbdfront.c +3 -2
@@ -129,8 +129,14 @@ static int xenkbd_probe(struct xenbus_device *dev,
 
 	if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-abs-pointer", "%d", &abs) < 0)
 		abs = 0;
-	if (abs)
-		xenbus_printf(XBT_NIL, dev->nodename, "request-abs-pointer", "1");
+	if (abs) {
+		ret = xenbus_printf(XBT_NIL, dev->nodename,
+					"request-abs-pointer", "1");

The second line of arguments should be aligned to the first parameter. I.e:

xenbus_printf(XBT_NIL, dev->nodename,

              "request-abs-pointer", "1");

See an example in xenkbd_backend_changed.

With that fixed:

drivers/input/misc/xen-kbdfront.c static int xenkbd_probe(struct xenbus_device *dev, · line 136

Quoted 2 lines
drivers/input/misc/xen-kbdfront.c +2 -0
+		if (ret) {
+			pr_warning("xenkbd: can't request abs-pointer");

Note that checkpatch.pl will print a warning here:

WARNING: Prefer pr_warn(... to pr_warning(...
#27: FILE: drivers/input/misc/xen-kbdfront.c:136:
+ pr_warning("xenkbd: can't request abs-pointer");

Although, I'm fine if you don't fix this one.

drivers/input/misc/xen-kbdfront.c static int xenkbd_probe(struct xenbus_device *dev, · line 142

Quoted 7 lines
drivers/input/misc/xen-kbdfront.c +3 -0
+			abs = 0;
+		}
+	}
 
 	/* keyboard */
 	kbd = input_allocate_device();

Regards,

Signature · 1 line
Julien Grall