Re: [PATCH v4 4/4] nvmem: eeprom: at25: export FRAM serial num
From: Jiří Prchal <hidden>
Date: 2021-05-20 06:56:43
Also in:
lkml
Here I'm completlly lost: On 20. 05. 21 7:52, Greg Kroah-Hartman wrote:
On Thu, May 20, 2021 at 07:47:14AM +0200, Jiri Prchal wrote:quoted
This exports serial number of FRAM in sysfs file named "sernum". Formatted in hex, each byte separated by space. Example: $ cat /sys/class/spi_master/spi0/spi0.0/sernumNo new Documentation/ABI/ entry for this?
No, should I do and how / where?
quoted
+static ssize_t sernum_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct at25_data *at25; + int i; + + at25 = dev_get_drvdata(dev); + for (i = 0; i < FM25_SN_LEN; i++) + buf += sprintf(buf, "%02x ", at25->sernum[i]); + sprintf(--buf, "\n"); + return (3 * i);No, that is not how sysfs files work, sorry. They are "one value per file". This looks like multiple values in the same file, why not just one file per "sernum"?
It's formatted by spaces. It's one long number like MAC addr, so is better to expose it as hex string without spaces? Or like MAC separated by colon?
Also, please use sysfs_emit() in the future.
Will do...
quoted
+} +static DEVICE_ATTR_RO(sernum); + static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count) { struct at25_data *at25 = priv;@@ -427,8 +441,13 @@ static int at25_probe(struct spi_device *spi) else at25->chip.flags |= EE_ADDR2; - if (id[8]) + if (id[8]) { at25->has_sernum = 1; + at25->sernum = kzalloc(FM25_SN_LEN, GFP_KERNEL); + if (!at25->sernum) + return -ENOMEM; + fm25_aux_read(at25, at25->sernum, FM25_RDSN, FM25_SN_LEN); + } else at25->has_sernum = 0;@@ -467,6 +486,13 @@ static int at25_probe(struct spi_device *spi) if (IS_ERR(at25->nvmem)) return PTR_ERR(at25->nvmem); + /* Export the FM25 serial number */ + if (at25->has_sernum) { + err = device_create_file(&spi->dev, &dev_attr_sernum);You just raced with userspace and lost :(
?
Please do this correctly, by setting the driver group if you need a file like this.
Any example, please?
thanks, greg k-h
thanks Jiri