Commit fc550e95 authored by Joe Jin's avatar Joe Jin Committed by Konrad Rzeszutek Wilk
Browse files

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]
Signed-off-by: default avatarKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: default avatarJoe Jin <joe.jin@oracle.com>
Tested-by: default avatarGurudas Pai <gurudas.pai@oracle.com>
Acked-by: default avatarIan Campbell <ian.campbell@citrix.com>
Cc: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
parent 731f3ab6
...@@ -562,26 +562,24 @@ static void xenfb_init_shared_page(struct xenfb_info *info, ...@@ -562,26 +562,24 @@ static void xenfb_init_shared_page(struct xenfb_info *info,
static int xenfb_connect_backend(struct xenbus_device *dev, static int xenfb_connect_backend(struct xenbus_device *dev,
struct xenfb_info *info) struct xenfb_info *info)
{ {
int ret, evtchn; int ret, evtchn, irq;
struct xenbus_transaction xbt; struct xenbus_transaction xbt;
ret = xenbus_alloc_evtchn(dev, &evtchn); ret = xenbus_alloc_evtchn(dev, &evtchn);
if (ret) if (ret)
return ret; return ret;
ret = bind_evtchn_to_irqhandler(evtchn, xenfb_event_handler, irq = bind_evtchn_to_irqhandler(evtchn, xenfb_event_handler,
0, dev->devicetype, info); 0, dev->devicetype, info);
if (ret < 0) { if (irq < 0) {
xenbus_free_evtchn(dev, evtchn); xenbus_free_evtchn(dev, evtchn);
xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler"); xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler");
return ret; return irq;
} }
info->irq = ret;
again: again:
ret = xenbus_transaction_start(&xbt); ret = xenbus_transaction_start(&xbt);
if (ret) { if (ret) {
xenbus_dev_fatal(dev, ret, "starting transaction"); xenbus_dev_fatal(dev, ret, "starting transaction");
return ret; goto unbind_irq;
} }
ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu", ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
virt_to_mfn(info->page)); virt_to_mfn(info->page));
...@@ -603,15 +601,18 @@ static int xenfb_connect_backend(struct xenbus_device *dev, ...@@ -603,15 +601,18 @@ static int xenfb_connect_backend(struct xenbus_device *dev,
if (ret == -EAGAIN) if (ret == -EAGAIN)
goto again; goto again;
xenbus_dev_fatal(dev, ret, "completing transaction"); xenbus_dev_fatal(dev, ret, "completing transaction");
return ret; goto unbind_irq;
} }
xenbus_switch_state(dev, XenbusStateInitialised); xenbus_switch_state(dev, XenbusStateInitialised);
info->irq = irq;
return 0; return 0;
error_xenbus: error_xenbus:
xenbus_transaction_end(xbt, 1); xenbus_transaction_end(xbt, 1);
xenbus_dev_fatal(dev, ret, "writing xenstore"); xenbus_dev_fatal(dev, ret, "writing xenstore");
unbind_irq:
unbind_from_irqhandler(irq, info);
return ret; return ret;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment