mtd: fix memory leak in mtd_dataflash
authorH Hartley Sweeten <hartleys@visionengravers.com>
Wed, 7 Oct 2009 21:08:08 +0000 (17:08 -0400)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Sat, 17 Oct 2009 14:41:11 +0000 (15:41 +0100)
commitd4702669b0b64b8fa7c91123639ec20d9592ee43
treea5f0be652b0a21b52194814de874a91d5cbe0358
parentf54d6336372b97d3624d1c5c179b2dd062472bd1
mtd: fix memory leak in mtd_dataflash

Fix a potential memory leak in mtd_dataflash driver.

The private data that is allocated when registering a DataFlash
device with the MTD subsystem is not released if an error occurs
when add_mtd_partitions() or add_mtd_device() is called.  Fix this
by adding an error path.  The memory is already released during a
remove.

Also, add a dev_set_drvdata(&spi->dev, NULL) before the kfree() so
that the spi device does not reference invalid data.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
drivers/mtd/devices/mtd_dataflash.c