Skip to contentSkip to conversation

eeprom: use devres for nvmem providers

PATCH In review Bartosz Golaszewski 1 participant 4 messages Sep 12, 2018 – Sep 20, 2018 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

v2 cover eeprom: use devres for nvmem providers

From: Bartosz Golaszewski <[email protected]>

While working on the nvmem framework recently I noticed that there are many providers that don't use the devm variant of nvmem_register(). This series contains relevant updates for eeprom drivers.

Note that these patches are independent from my other nvmem series[1].

[1] https://lkml.org/lkml/2018/9/12/265

v1 -> v2:
- fix an invalid devm_ free in patch 1

Bartosz Golaszewski (2):
eeprom: eeprom_93xx46: use resource management
eeprom: at25: use devm_nvmem_register()

 drivers/misc/eeprom/at25.c          |  3 +--
 drivers/misc/eeprom/eeprom_93xx46.c | 19 +++++--------------
 2 files changed, 6 insertions(+), 16 deletions(-)
Signature · 1 line
2.18.0
#1 lore raw

PATCH v2 1/2 eeprom: eeprom_93xx46: use resource management

From: Bartosz Golaszewski <[email protected]>

Use resource managed variants of nvmem_register() and kzalloc().

---
 drivers/misc/eeprom/eeprom_93xx46.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)
drivers/misc/eeprom/eeprom_93xx46.c +5 -14
index 38766968bfa2..c6dd9ad9bf7b 100644
@@ -439,7 +439,7 @@ static int eeprom_93xx46_probe(struct spi_device *spi)
 		return -ENODEV;
 	}
 
-	edev = kzalloc(sizeof(*edev), GFP_KERNEL);
+	edev = devm_kzalloc(&spi->dev, sizeof(*edev), GFP_KERNEL);
 	if (!edev)
 		return -ENOMEM;
 
@@ -449,8 +449,7 @@ static int eeprom_93xx46_probe(struct spi_device *spi)
 		edev->addrlen = 6;
 	else {
 		dev_err(&spi->dev, "unspecified address type\n");
-		err = -EINVAL;
-		goto fail;
+		return -EINVAL;
 	}
 
 	mutex_init(&edev->lock);
@@ -473,11 +472,9 @@ static int eeprom_93xx46_probe(struct spi_device *spi)
 	edev->nvmem_config.word_size = 1;
 	edev->nvmem_config.size = edev->size;
 
-	edev->nvmem = nvmem_register(&edev->nvmem_config);
-	if (IS_ERR(edev->nvmem)) {
-		err = PTR_ERR(edev->nvmem);
-		goto fail;
-	}
+	edev->nvmem = devm_nvmem_register(&spi->dev, &edev->nvmem_config);
+	if (IS_ERR(edev->nvmem))
+		return PTR_ERR(edev->nvmem);
 
 	dev_info(&spi->dev, "%d-bit eeprom %s\n",
 		(pd->flags & EE_ADDR8) ? 8 : 16,
@@ -490,21 +487,15 @@ static int eeprom_93xx46_probe(struct spi_device *spi)
 
 	spi_set_drvdata(spi, edev);
 	return 0;
-fail:
-	kfree(edev);
-	return err;
 }
 
 static int eeprom_93xx46_remove(struct spi_device *spi)
 {
 	struct eeprom_93xx46_dev *edev = spi_get_drvdata(spi);
 
-	nvmem_unregister(edev->nvmem);
-
 	if (!(edev->pdata->flags & EE_READONLY))
 		device_remove_file(&spi->dev, &dev_attr_erase);
 
-	kfree(edev);
 	return 0;
 }
 
Signature · 1 line
2.18.0
#2 lore raw

PATCH v2 2/2 eeprom: at25: use devm_nvmem_register()

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Use the resource managed variant of nvmem_register().

---
 drivers/misc/eeprom/at25.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/misc/eeprom/at25.c +1 -2
index 840afb398f9e..d874df72853f 100644
@@ -366,7 +366,7 @@ static int at25_probe(struct spi_device *spi)
 	at25->nvmem_config.word_size = 1;
 	at25->nvmem_config.size = chip.byte_len;
 
-	at25->nvmem = nvmem_register(&at25->nvmem_config);
+	at25->nvmem = devm_nvmem_register(&spi->dev, &at25->nvmem_config);
 	if (IS_ERR(at25->nvmem))
 		return PTR_ERR(at25->nvmem);
 
@@ -384,7 +384,6 @@ static int at25_remove(struct spi_device *spi)
 	struct at25_data	*at25;
 
 	at25 = spi_get_drvdata(spi);
-	nvmem_unregister(at25->nvmem);
 
 	return 0;
 }
Signature · 1 line
2.18.0
#3 lore raw
In reply to Bartosz Golaszewski

2018-09-12 10:04 GMT+02:00 Bartosz Golaszewski <[email protected]>:

Quoted 17 lines

From: Bartosz Golaszewski <[email protected]>

While working on the nvmem framework recently I noticed that there are many providers that don't use the devm variant of nvmem_register(). This series contains relevant updates for eeprom drivers.

Note that these patches are independent from my other nvmem series[1].

[1] https://lkml.org/lkml/2018/9/12/265

v1 -> v2:
- fix an invalid devm_ free in patch 1

Bartosz Golaszewski (2):
eeprom: eeprom_93xx46: use resource management
eeprom: at25: use devm_nvmem_register()

Quoted 7 lines
 drivers/misc/eeprom/at25.c          |  3 +--
 drivers/misc/eeprom/eeprom_93xx46.c | 19 +++++--------------
 2 files changed, 6 insertions(+), 16 deletions(-)

--
2.18.0

Srinivas,

Greg will probably be busy this cycle, so in case he misses those - can you send them together with your nvmem pull request? They don't depend on my other series in any way.

Bart