Skip to contentSkip to conversation

misc: at25: Fix issues brought with FRAM support

PATCH In review Andy Shevchenko 2 participants 7 messages Nov 25, 2021 – Dec 1, 2021 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

cover misc: at25: Fix issues brought with FRAM support

A few fixes to the AT25 driver that have been brought by FRAM support series.

Andy Shevchenko (3):
misc: at25: Make driver OF independent again
misc: at25: Don't copy garbage to the at25->chip in FRAM case
misc: at25: Check proper value of chip length in FRAM case

 drivers/misc/eeprom/at25.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
Signature · 1 line
2.33.0
#1 lore raw

PATCH 1/3 misc: at25: Make driver OF independent again

The commit f60e7074902a ("misc: at25: Make use of device property API") made a good job by enabling the driver for non-OF platforms, but the recent commit 604288bc6196 ("nvmem: eeprom: at25: fix type compiler warnings") brought that back.

Restore greatness of the driver once again.

Fixes eab61fb1cc2e ("nvmem: eeprom: at25: fram discovery simplification")
Fixes fd307a4ad332 ("nvmem: prepare basics for FRAM support")
---
 drivers/misc/eeprom/at25.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/misc/eeprom/at25.c +6 -7
index 632325474233..57599eac2f71 100644
@@ -17,8 +17,6 @@
 #include <linux/spi/spi.h>
 #include <linux/spi/eeprom.h>
 #include <linux/property.h>
-#include <linux/of.h>
-#include <linux/of_device.h>
 #include <linux/math.h>
 
 /*
@@ -381,13 +379,14 @@ static int at25_probe(struct spi_device *spi)
 	int			sr;
 	u8 id[FM25_ID_LEN];
 	u8 sernum[FM25_SN_LEN];
+	bool is_fram;
 	int i;
-	const struct of_device_id *match;
-	bool is_fram = 0;
 
-	match = of_match_device(of_match_ptr(at25_of_match), &spi->dev);
-	if (match && !strcmp(match->compatible, "cypress,fm25"))
-		is_fram = 1;
+	err = device_property_match_string(&spi->dev, "compatible", "cypress,fm25");
+	if (err >= 0)
+		is_fram = true;
+	else
+		is_fram = false;
 
 	/* Chip description */
 	if (!spi->dev.platform_data) {
Signature · 1 line
2.33.0
#2 lore raw

PATCH 2/3 misc: at25: Don't copy garbage to the at25->chip in FRAM case

In reply to Andy Shevchenko

Even if we know that we are going to fill everything later on it's bad style and fragile to copy garbage from the stack to the data structure that will be used in the driver.

Fixes fd307a4ad332 ("nvmem: prepare basics for FRAM support")
---
 drivers/misc/eeprom/at25.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/misc/eeprom/at25.c +4 -1
index 57599eac2f71..f0b0efc30ee6 100644
@@ -390,7 +390,10 @@ static int at25_probe(struct spi_device *spi)
 
 	/* Chip description */
 	if (!spi->dev.platform_data) {
-		if (!is_fram) {
+		if (is_fram) {
+			/* We file fields for FRAM case later on */
+			memset(&chip, 0, sizeof(chip));
+		} else {
 			err = at25_fw_to_chip(&spi->dev, &chip);
 			if (err)
 				return err;
Signature · 1 line
2.33.0
#3 lore raw

PATCH 3/3 misc: at25: Check proper value of chip length in FRAM case

In reply to Andy Shevchenko

Obviously the byte_len value should be checked from the chip and not from at25->chip.

Fixes fd307a4ad332 ("nvmem: prepare basics for FRAM support")
---
 drivers/misc/eeprom/at25.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/eeprom/at25.c +2 -2
index f0b0efc30ee6..e21216541b0f 100644
@@ -433,9 +433,9 @@ static int at25_probe(struct spi_device *spi)
 			dev_err(&spi->dev, "Error: unsupported size (id %02x)\n", id[7]);
 			return -ENODEV;
 		}
-		chip.byte_len = int_pow(2, id[7] - 0x21 + 4) * 1024;
 
-		if (at25->chip.byte_len > 64 * 1024)
+		chip.byte_len = int_pow(2, id[7] - 0x21 + 4) * 1024;
+		if (chip.byte_len > 64 * 1024)
 			at25->chip.flags |= EE_ADDR3;
 		else
 			at25->chip.flags |= EE_ADDR2;
Signature · 1 line
2.33.0
maintainer Acked-by on the v1 series
#4 lore raw
In reply to Andy Shevchenko
Quoted 7 lines · Andy Shevchenko

A few fixes to the AT25 driver that have been brought by FRAM support series.

Andy Shevchenko (3):
misc: at25: Make driver OF independent again
misc: at25: Don't copy garbage to the at25->chip in FRAM case
misc: at25: Check proper value of chip length in FRAM case

Looks all good to me,

#5 lore raw
Quoted 5 lines · Arnd Bergmann
Quoted 3 lines · Andy Shevchenko

A few fixes to the AT25 driver that have been brought by FRAM support series.

Quoted 8 lines
Quoted 4 lines

Andy Shevchenko (3):
misc: at25: Make driver OF independent again
misc: at25: Don't copy garbage to the at25->chip in FRAM case
misc: at25: Check proper value of chip length in FRAM case

Looks all good to me,

Thank you!
There is also cleanup series if you are interested of looking into...

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw
In reply to Andy Shevchenko
Quoted 9 lines · Andy Shevchenko

A few fixes to the AT25 driver that have been brought by FRAM support series.

Andy Shevchenko (3):
misc: at25: Make driver OF independent again
misc: at25: Don't copy garbage to the at25->chip in FRAM case
misc: at25: Check proper value of chip length in FRAM case

 drivers/misc/eeprom/at25.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

Greg, it seem under your realm, can you apply this for current cycle, please?

Signature · 2 lines
With Best Regards,
Andy Shevchenko