[S390] cio: fix memleak in subchannel validation
authorSebastian Ott <sebott@linux.vnet.ibm.com>
Fri, 11 Sep 2009 08:28:24 +0000 (10:28 +0200)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Fri, 11 Sep 2009 08:29:39 +0000 (10:29 +0200)
When scanning for new subchannels we have a code path where we allocate
memory for a struct subchannel, set the device name (which is dynamically
allocated now) and do a check if the underlying device is blacklisted - if
so we free the subchannel structure.
Since we have not set up refcounting at this stage, the device name's memory
is lost. Fix this by moving the dev_set_name after the blacklist test.

Note: With this patch the init_name for the console subchannel becomes
virtually obsolete.

Signed-off-by: Sebastian Ott <sebott@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
drivers/s390/cio/cio.c
drivers/s390/cio/css.c

index 390b4e96fd0d1d6085cac76e7d1b5857036c34e1..fe18ef691bb781ee3ed6666353d2119736bd1490 100644 (file)
@@ -564,11 +564,6 @@ int cio_validate_subchannel(struct subchannel *sch, struct subchannel_id schid)
                        goto out;
        }
        mutex_init(&sch->reg_mutex);
-       /* Set a name for the subchannel */
-       if (cio_is_console(schid))
-               sch->dev.init_name = cio_get_console_sch_name(schid);
-       else
-               dev_set_name(&sch->dev, "0.%x.%04x", schid.ssid, schid.sch_no);
 
        /*
         * The first subchannel that is not-operational (ccode==3)
index 40d4b3093b718cacbaca1c514e999aed44e10fca..0dc6f6d26287d0f12ca97537b53ad7ca4d34bea6 100644 (file)
@@ -183,6 +183,11 @@ static int css_sch_device_register(struct subchannel *sch)
        int ret;
 
        mutex_lock(&sch->reg_mutex);
+       if (cio_is_console(sch->schid))
+               sch->dev.init_name = cio_get_console_sch_name(sch->schid);
+       else
+               dev_set_name(&sch->dev, "0.%x.%04x", sch->schid.ssid,
+                            sch->schid.sch_no);
        ret = device_register(&sch->dev);
        mutex_unlock(&sch->reg_mutex);
        return ret;