Skip to contentSkip to conversation

linux-2.6.18/fb: fix potential memory leak

PATCH New Jan Beulich 1 participant 1 message Feb 8, 2011 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-2.6.18/fb: fix potential memory leak

From: Joe Jin <[email protected]>

This patch fixes a potential memory leak when xenfb connect to the backend fails.

Thanks for Ian's review and comments.

[v2: reworded the commit message a bit]

Made apply to linux-2.6.18-xen.hg.

drivers/xen/fbfront/xenfb.c +10 -8
@@ -735,23 +735,22 @@ static void xenfb_init_shared_page(struc
 static int xenfb_connect_backend(struct xenbus_device *dev,
 				 struct xenfb_info *info)
 {
-	int ret;
+	int ret, irq;
 	struct xenbus_transaction xbt;
 
-	ret = bind_listening_port_to_irqhandler(
+	irq = bind_listening_port_to_irqhandler(
 		dev->otherend_id, xenfb_event_handler, 0, "xenfb", info);
-	if (ret < 0) {
-		xenbus_dev_fatal(dev, ret,
+	if (irq < 0) {
+		xenbus_dev_fatal(dev, irq,
 				 "bind_listening_port_to_irqhandler");
-		return ret;
+		return irq;
 	}
-	info->irq = ret;
 
  again:
 	ret = xenbus_transaction_start(&xbt);
 	if (ret) {
 		xenbus_dev_fatal(dev, ret, "starting transaction");
-		return ret;
+		goto unbind_irq;
 	}
 	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
 			    virt_to_mfn(info->page));
@@ -773,15 +772,18 @@ static int xenfb_connect_backend(struct 
 		if (ret == -EAGAIN)
 			goto again;
 		xenbus_dev_fatal(dev, ret, "completing transaction");
-		return ret;
+		goto unbind_irq;
 	}
 
+	info->irq = irq;
 	xenbus_switch_state(dev, XenbusStateInitialised);
 	return 0;
 
  error_xenbus:
 	xenbus_transaction_end(xbt, 1);
 	xenbus_dev_fatal(dev, ret, "writing xenstore");
+ unbind_irq:
+	unbind_from_irqhandler(irq, info);
 	return ret;
 }
 

From: Joe Jin <[email protected]>
Subject: xen/fb: fix potential memory leak

This patch fixes a potential memory leak when xenfb connect to the backend fails.

Thanks for Ian's review and comments.

[v2: reworded the commit message a bit]

Made apply to linux-2.6.18-xen.hg.

drivers/xen/fbfront/xenfb.c +10 -8
@@ -735,23 +735,22 @@ static void xenfb_init_shared_page(struc
 static int xenfb_connect_backend(struct xenbus_device *dev,
 				 struct xenfb_info *info)
 {
-	int ret;
+	int ret, irq;
 	struct xenbus_transaction xbt;
 
-	ret = bind_listening_port_to_irqhandler(
+	irq = bind_listening_port_to_irqhandler(
 		dev->otherend_id, xenfb_event_handler, 0, "xenfb", info);
-	if (ret < 0) {
-		xenbus_dev_fatal(dev, ret,
+	if (irq < 0) {
+		xenbus_dev_fatal(dev, irq,
 				 "bind_listening_port_to_irqhandler");
-		return ret;
+		return irq;
 	}
-	info->irq = ret;
 
  again:
 	ret = xenbus_transaction_start(&xbt);
 	if (ret) {
 		xenbus_dev_fatal(dev, ret, "starting transaction");
-		return ret;
+		goto unbind_irq;
 	}
 	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
 			    virt_to_mfn(info->page));
@@ -773,15 +772,18 @@ static int xenfb_connect_backend(struct 
 		if (ret == -EAGAIN)
 			goto again;
 		xenbus_dev_fatal(dev, ret, "completing transaction");
-		return ret;
+		goto unbind_irq;
 	}
 
+	info->irq = irq;
 	xenbus_switch_state(dev, XenbusStateInitialised);
 	return 0;
 
  error_xenbus:
 	xenbus_transaction_end(xbt, 1);
 	xenbus_dev_fatal(dev, ret, "writing xenstore");
+ unbind_irq:
+	unbind_from_irqhandler(irq, info);
 	return ret;
 }
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel