提交 01fe7b43 编写于 作者: N Nikolay Balandin 提交者: Greg Kroah-Hartman

drivers/misc: at25: convert to use devm_kzalloc

Use devm_kzalloc to make cleanup paths simpler
Signed-off-by: NNikolay Balandin <nbalandin@dev.rtsoft.ru>
Reviewed-by: NAndy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: NJingoo Han <jg1.han@samsung.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 f0ac2363
...@@ -371,11 +371,10 @@ static int at25_probe(struct spi_device *spi) ...@@ -371,11 +371,10 @@ static int at25_probe(struct spi_device *spi)
if (np) { if (np) {
err = at25_np_to_chip(&spi->dev, np, &chip); err = at25_np_to_chip(&spi->dev, np, &chip);
if (err) if (err)
goto fail; return err;
} else { } else {
dev_err(&spi->dev, "Error: no chip description\n"); dev_err(&spi->dev, "Error: no chip description\n");
err = -ENODEV; return -ENODEV;
goto fail;
} }
} else } else
chip = *(struct spi_eeprom *)spi->dev.platform_data; chip = *(struct spi_eeprom *)spi->dev.platform_data;
...@@ -389,8 +388,7 @@ static int at25_probe(struct spi_device *spi) ...@@ -389,8 +388,7 @@ static int at25_probe(struct spi_device *spi)
addrlen = 3; addrlen = 3;
else { else {
dev_dbg(&spi->dev, "unsupported address type\n"); dev_dbg(&spi->dev, "unsupported address type\n");
err = -EINVAL; return -EINVAL;
goto fail;
} }
/* Ping the chip ... the status register is pretty portable, /* Ping the chip ... the status register is pretty portable,
...@@ -400,14 +398,12 @@ static int at25_probe(struct spi_device *spi) ...@@ -400,14 +398,12 @@ static int at25_probe(struct spi_device *spi)
sr = spi_w8r8(spi, AT25_RDSR); sr = spi_w8r8(spi, AT25_RDSR);
if (sr < 0 || sr & AT25_SR_nRDY) { if (sr < 0 || sr & AT25_SR_nRDY) {
dev_dbg(&spi->dev, "rdsr --> %d (%02x)\n", sr, sr); dev_dbg(&spi->dev, "rdsr --> %d (%02x)\n", sr, sr);
err = -ENXIO; return -ENXIO;
goto fail;
} }
if (!(at25 = kzalloc(sizeof *at25, GFP_KERNEL))) { at25 = devm_kzalloc(&spi->dev, sizeof(struct at25_data), GFP_KERNEL);
err = -ENOMEM; if (!at25)
goto fail; return -ENOMEM;
}
mutex_init(&at25->lock); mutex_init(&at25->lock);
at25->chip = chip; at25->chip = chip;
...@@ -439,7 +435,7 @@ static int at25_probe(struct spi_device *spi) ...@@ -439,7 +435,7 @@ static int at25_probe(struct spi_device *spi)
err = sysfs_create_bin_file(&spi->dev.kobj, &at25->bin); err = sysfs_create_bin_file(&spi->dev.kobj, &at25->bin);
if (err) if (err)
goto fail; return err;
if (chip.setup) if (chip.setup)
chip.setup(&at25->mem, chip.context); chip.setup(&at25->mem, chip.context);
...@@ -453,10 +449,6 @@ static int at25_probe(struct spi_device *spi) ...@@ -453,10 +449,6 @@ static int at25_probe(struct spi_device *spi)
(chip.flags & EE_READONLY) ? " (readonly)" : "", (chip.flags & EE_READONLY) ? " (readonly)" : "",
at25->chip.page_size); at25->chip.page_size);
return 0; return 0;
fail:
dev_dbg(&spi->dev, "probe err %d\n", err);
kfree(at25);
return err;
} }
static int at25_remove(struct spi_device *spi) static int at25_remove(struct spi_device *spi)
...@@ -465,7 +457,6 @@ static int at25_remove(struct spi_device *spi) ...@@ -465,7 +457,6 @@ static int at25_remove(struct spi_device *spi)
at25 = spi_get_drvdata(spi); at25 = spi_get_drvdata(spi);
sysfs_remove_bin_file(&spi->dev.kobj, &at25->bin); sysfs_remove_bin_file(&spi->dev.kobj, &at25->bin);
kfree(at25);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册