From: Olaf Hering <olaf@aepfle.de>
To: konrad.wilk@oracle.com
Cc: linux-kernel@vger.kernel.org, xen-devel@lists.xen.org,
jbeulich@suse.com, Olaf Hering <olaf@aepfle.de>
Subject: [PATCH] xen/blkback: prevent repeated backend_changed invocations
Date: Tue, 11 Dec 2012 21:50:26 +0100 [thread overview]
Message-ID: <1355259026-16946-1-git-send-email-olaf@aepfle.de> (raw)
backend_changed might be called multiple times, which will leak
be->mode. Make sure it will be called only once. Remove some unneeded
checks. Also the be->mode string was leaked, release the memory on
device shutdown.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
incorporate all comments from Jan.
fold the oneline change to xen_blkbk_remove into this change
now its compile tested.
drivers/block/xen-blkback/xenbus.c | 69 ++++++++++++++++++--------------------
1 file changed, 33 insertions(+), 36 deletions(-)
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index f58434c..5ca77c3 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -28,6 +28,7 @@ struct backend_info {
unsigned major;
unsigned minor;
char *mode;
+ unsigned alive;
};
static struct kmem_cache *xen_blkif_cachep;
@@ -366,6 +367,7 @@ static int xen_blkbk_remove(struct xenbus_device *dev)
be->blkif = NULL;
}
+ kfree(be->mode);
kfree(be);
dev_set_drvdata(&dev->dev, NULL);
return 0;
@@ -501,10 +503,14 @@ static void backend_changed(struct xenbus_watch *watch,
= container_of(watch, struct backend_info, backend_watch);
struct xenbus_device *dev = be->dev;
int cdrom = 0;
- char *device_type;
+ char *device_type, *p;
+ long handle;
DPRINTK("");
+ if (be->alive)
+ return;
+
err = xenbus_scanf(XBT_NIL, dev->nodename, "physical-device", "%x:%x",
&major, &minor);
if (XENBUS_EXIST_ERR(err)) {
@@ -520,12 +526,7 @@ static void backend_changed(struct xenbus_watch *watch,
return;
}
- if ((be->major || be->minor) &&
- ((be->major != major) || (be->minor != minor))) {
- pr_warn(DRV_PFX "changing physical device (from %x:%x to %x:%x) not supported.\n",
- be->major, be->minor, major, minor);
- return;
- }
+ be->alive = 1;
be->mode = xenbus_read(XBT_NIL, dev->nodename, "mode", NULL);
if (IS_ERR(be->mode)) {
@@ -541,39 +542,35 @@ static void backend_changed(struct xenbus_watch *watch,
kfree(device_type);
}
- if (be->major == 0 && be->minor == 0) {
- /* Front end dir is a number, which is used as the handle. */
-
- char *p = strrchr(dev->otherend, '/') + 1;
- long handle;
- err = strict_strtoul(p, 0, &handle);
- if (err)
- return;
-
- be->major = major;
- be->minor = minor;
+ /* Front end dir is a number, which is used as the handle. */
+ p = strrchr(dev->otherend, '/') + 1;
+ err = strict_strtoul(p, 0, &handle);
+ if (err)
+ return;
- err = xen_vbd_create(be->blkif, handle, major, minor,
- (NULL == strchr(be->mode, 'w')), cdrom);
- if (err) {
- be->major = 0;
- be->minor = 0;
- xenbus_dev_fatal(dev, err, "creating vbd structure");
- return;
- }
+ be->major = major;
+ be->minor = minor;
- err = xenvbd_sysfs_addif(dev);
- if (err) {
- xen_vbd_free(&be->blkif->vbd);
- be->major = 0;
- be->minor = 0;
- xenbus_dev_fatal(dev, err, "creating sysfs entries");
- return;
- }
+ err = xen_vbd_create(be->blkif, handle, major, minor,
+ (NULL == strchr(be->mode, 'w')), cdrom);
+ if (err) {
+ be->major = 0;
+ be->minor = 0;
+ xenbus_dev_fatal(dev, err, "creating vbd structure");
+ return;
+ }
- /* We're potentially connected now */
- xen_update_blkif_status(be->blkif);
+ err = xenvbd_sysfs_addif(dev);
+ if (err) {
+ xen_vbd_free(&be->blkif->vbd);
+ be->major = 0;
+ be->minor = 0;
+ xenbus_dev_fatal(dev, err, "creating sysfs entries");
+ return;
}
+
+ /* We're potentially connected now */
+ xen_update_blkif_status(be->blkif);
}
--
1.8.0.1
next reply other threads:[~2012-12-11 20:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-11 20:50 Olaf Hering [this message]
2012-12-12 9:42 ` [PATCH] xen/blkback: prevent repeated backend_changed invocations Jan Beulich
2012-12-12 9:47 ` Olaf Hering
2012-12-12 9:53 ` Jan Beulich
2012-12-12 10:34 ` [Xen-devel] " Ian Campbell
2012-12-12 10:45 ` Olaf Hering
2012-12-13 15:02 ` Jan Beulich
2012-12-19 20:14 ` Konrad Rzeszutek Wilk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1355259026-16946-1-git-send-email-olaf@aepfle.de \
--to=olaf@aepfle.de \
--cc=jbeulich@suse.com \
--cc=konrad.wilk@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox