* [PATCH 2/3] soc: kvx: Fix memory leaks
2023-07-11 9:11 [PATCH 1/3] soc: kvx: Rename function to match global variable Jules Maselbas
@ 2023-07-11 9:11 ` Jules Maselbas
2023-07-11 9:11 ` [PATCH 3/3] soc: kvx: Add board_sn global var from OTP Jules Maselbas
2023-07-26 12:18 ` [PATCH 1/3] soc: kvx: Rename function to match global variable Sascha Hauer
2 siblings, 0 replies; 6+ messages in thread
From: Jules Maselbas @ 2023-07-11 9:11 UTC (permalink / raw)
To: barebox; +Cc: Jules Maselbas
When calling nvmem_cell_get_and_read the resulting memory must be freed.
Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
drivers/soc/kvx/kvx_socinfo.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/soc/kvx/kvx_socinfo.c b/drivers/soc/kvx/kvx_socinfo.c
index fc7ba1c1b9..496e817755 100644
--- a/drivers/soc/kvx/kvx_socinfo.c
+++ b/drivers/soc/kvx/kvx_socinfo.c
@@ -102,6 +102,7 @@ static int kvx_read_mppa_id(struct device_node *socinfo)
ews_val = (ews_val >> 32) | (ews_val << 32);
wafer_id = (ews_val >> EWS_WAFER_ID_SHIFT) & EWS_WAFER_ID_MASK;
base38_decode(lot_id, ews_val & EWS_LOT_ID_MASK, LOT_ID_STR_LEN);
+ free(cell_val64);
cell_val32 = (u32 *) nvmem_cell_get_and_read(socinfo, "ft_fuse", 4);
if (IS_ERR(cell_val32)) {
@@ -112,6 +113,7 @@ static int kvx_read_mppa_id(struct device_node *socinfo)
ft_val = *cell_val32;
device_id = (ft_val >> FT_DEVICE_ID_SHIFT) & FT_DEVICE_ID_MASK;
base38_decode(&com_ap, (ft_val >> FT_COM_AP_SHIFT) & FT_COM_AP_MASK, 1);
+ free(cell_val32);
kvx_mppa_id = basprintf("%sA-%d%c-%03d", lot_id, wafer_id, com_ap,
device_id);
--
2.17.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/3] soc: kvx: Add board_sn global var from OTP
2023-07-11 9:11 [PATCH 1/3] soc: kvx: Rename function to match global variable Jules Maselbas
2023-07-11 9:11 ` [PATCH 2/3] soc: kvx: Fix memory leaks Jules Maselbas
@ 2023-07-11 9:11 ` Jules Maselbas
2023-07-26 12:26 ` Sascha Hauer
2023-07-26 12:18 ` [PATCH 1/3] soc: kvx: Rename function to match global variable Sascha Hauer
2 siblings, 1 reply; 6+ messages in thread
From: Jules Maselbas @ 2023-07-11 9:11 UTC (permalink / raw)
To: barebox; +Cc: Jules Maselbas
Add the magic variable "kvx.board_sn" that will reflect the board serial
number stored in OTP.
Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
drivers/soc/kvx/kvx_socinfo.c | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/drivers/soc/kvx/kvx_socinfo.c b/drivers/soc/kvx/kvx_socinfo.c
index 496e817755..87c20c327b 100644
--- a/drivers/soc/kvx/kvx_socinfo.c
+++ b/drivers/soc/kvx/kvx_socinfo.c
@@ -33,9 +33,11 @@
static char *kvx_mppa_id;
static char *kvx_arch_rev;
+static char *kvx_board_sn;
BAREBOX_MAGICVAR(kvx.arch_rev, "KVX architecture revision");
BAREBOX_MAGICVAR(kvx.mppa_id, "KVX MPPA chip id");
+BAREBOX_MAGICVAR(kvx.board_sn, "KVX board sn");
static void kvx_soc_info_read_revision(void)
{
@@ -123,11 +125,40 @@ static int kvx_read_mppa_id(struct device_node *socinfo)
return 0;
}
+static int kvx_read_board_sn(struct device_node *socinfo)
+{
+ struct nvmem_cell *cell;
+ size_t len;
+ char *sn;
+
+ cell = of_nvmem_cell_get(socinfo, "board_sn");
+ if (IS_ERR(cell)) {
+ pr_debug("Fail to get board_sn cell\n");
+ return PTR_ERR(cell);
+ }
+
+ sn = (char *)nvmem_cell_read(cell, &len);
+ nvmem_cell_put(cell);
+ if (IS_ERR(sn)) {
+ pr_debug("Fail to read board_sn\n");
+ return PTR_ERR(sn);
+ }
+
+ kvx_board_sn = xzalloc(len + 1);
+ memcpy(kvx_board_sn, sn, len);
+ globalvar_add_simple_string("kvx.board_sn", &kvx_board_sn);
+ free(sn);
+
+ return 0;
+}
+
static int kvx_socinfo_probe(struct device *dev)
{
kvx_soc_info_read_revision();
- return kvx_read_serial(dev->of_node);
+ kvx_read_board_sn(dev->device_node);
+
+ return kvx_read_mppa_id(dev->device_node);
}
static const struct of_device_id kvx_socinfo_dt_ids[] = {
--
2.17.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] soc: kvx: Add board_sn global var from OTP
2023-07-11 9:11 ` [PATCH 3/3] soc: kvx: Add board_sn global var from OTP Jules Maselbas
@ 2023-07-26 12:26 ` Sascha Hauer
2023-07-26 19:00 ` Jules Maselbas
0 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2023-07-26 12:26 UTC (permalink / raw)
To: Jules Maselbas; +Cc: barebox, Jules Maselbas
On Tue, Jul 11, 2023 at 11:11:23AM +0200, Jules Maselbas wrote:
> Add the magic variable "kvx.board_sn" that will reflect the board serial
> number stored in OTP.
>
> Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
> ---
> drivers/soc/kvx/kvx_socinfo.c | 33 ++++++++++++++++++++++++++++++++-
> 1 file changed, 32 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/soc/kvx/kvx_socinfo.c b/drivers/soc/kvx/kvx_socinfo.c
> index 496e817755..87c20c327b 100644
> --- a/drivers/soc/kvx/kvx_socinfo.c
> +++ b/drivers/soc/kvx/kvx_socinfo.c
> @@ -33,9 +33,11 @@
>
> static char *kvx_mppa_id;
> static char *kvx_arch_rev;
> +static char *kvx_board_sn;
>
> BAREBOX_MAGICVAR(kvx.arch_rev, "KVX architecture revision");
> BAREBOX_MAGICVAR(kvx.mppa_id, "KVX MPPA chip id");
> +BAREBOX_MAGICVAR(kvx.board_sn, "KVX board sn");
>
> static void kvx_soc_info_read_revision(void)
> {
> @@ -123,11 +125,40 @@ static int kvx_read_mppa_id(struct device_node *socinfo)
> return 0;
> }
>
> +static int kvx_read_board_sn(struct device_node *socinfo)
> +{
> + struct nvmem_cell *cell;
> + size_t len;
> + char *sn;
> +
> + cell = of_nvmem_cell_get(socinfo, "board_sn");
> + if (IS_ERR(cell)) {
> + pr_debug("Fail to get board_sn cell\n");
> + return PTR_ERR(cell);
> + }
> +
> + sn = (char *)nvmem_cell_read(cell, &len);
> + nvmem_cell_put(cell);
> + if (IS_ERR(sn)) {
> + pr_debug("Fail to read board_sn\n");
> + return PTR_ERR(sn);
> + }
> +
> + kvx_board_sn = xzalloc(len + 1);
> + memcpy(kvx_board_sn, sn, len);
> + globalvar_add_simple_string("kvx.board_sn", &kvx_board_sn);
> + free(sn);
> +
> + return 0;
> +}
> +
> static int kvx_socinfo_probe(struct device *dev)
> {
> kvx_soc_info_read_revision();
>
> - return kvx_read_serial(dev->of_node);
> + kvx_read_board_sn(dev->device_node);
> +
> + return kvx_read_mppa_id(dev->device_node);
> }
Ah, ok. Here is the missing hunk from patch 1. I just fixed this up
while applying.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] soc: kvx: Add board_sn global var from OTP
2023-07-26 12:26 ` Sascha Hauer
@ 2023-07-26 19:00 ` Jules Maselbas
0 siblings, 0 replies; 6+ messages in thread
From: Jules Maselbas @ 2023-07-26 19:00 UTC (permalink / raw)
To: barebox, Sascha Hauer
On July 26, 2023 2:26:38 PM GMT+02:00, Sascha Hauer <sha@pengutronix.de> wrote:
> On Tue, Jul 11, 2023 at 11:11:23AM +0200, Jules Maselbas wrote:
> > Add the magic variable "kvx.board_sn" that will reflect the board serial
> > number stored in OTP.
> >
> > Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
> > ---
> > drivers/soc/kvx/kvx_socinfo.c | 33 ++++++++++++++++++++++++++++++++-
> > 1 file changed, 32 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/soc/kvx/kvx_socinfo.c b/drivers/soc/kvx/kvx_socinfo.c
> > index 496e817755..87c20c327b 100644
> > --- a/drivers/soc/kvx/kvx_socinfo.c
> > +++ b/drivers/soc/kvx/kvx_socinfo.c
> > @@ -33,9 +33,11 @@
> >
> > static char *kvx_mppa_id;
> > static char *kvx_arch_rev;
> > +static char *kvx_board_sn;
> >
> > BAREBOX_MAGICVAR(kvx.arch_rev, "KVX architecture revision");
> > BAREBOX_MAGICVAR(kvx.mppa_id, "KVX MPPA chip id");
> > +BAREBOX_MAGICVAR(kvx.board_sn, "KVX board sn");
> >
> > static void kvx_soc_info_read_revision(void)
> > {
> > @@ -123,11 +125,40 @@ static int kvx_read_mppa_id(struct device_node *socinfo)
> > return 0;
> > }
> >
> > +static int kvx_read_board_sn(struct device_node *socinfo)
> > +{
> > + struct nvmem_cell *cell;
> > + size_t len;
> > + char *sn;
> > +
> > + cell = of_nvmem_cell_get(socinfo, "board_sn");
> > + if (IS_ERR(cell)) {
> > + pr_debug("Fail to get board_sn cell\n");
> > + return PTR_ERR(cell);
> > + }
> > +
> > + sn = (char *)nvmem_cell_read(cell, &len);
> > + nvmem_cell_put(cell);
> > + if (IS_ERR(sn)) {
> > + pr_debug("Fail to read board_sn\n");
> > + return PTR_ERR(sn);
> > + }
> > +
> > + kvx_board_sn = xzalloc(len + 1);
> > + memcpy(kvx_board_sn, sn, len);
> > + globalvar_add_simple_string("kvx.board_sn", &kvx_board_sn);
> > + free(sn);
> > +
> > + return 0;
> > +}
> > +
> > static int kvx_socinfo_probe(struct device *dev)
> > {
> > kvx_soc_info_read_revision();
> >
> > - return kvx_read_serial(dev->of_node);
> > + kvx_read_board_sn(dev->device_node);
> > +
> > + return kvx_read_mppa_id(dev->device_node);
> > }
>
> Ah, ok. Here is the missing hunk from patch 1. I just fixed this up
> while applying.
Thanks
>
> Sascha
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] soc: kvx: Rename function to match global variable
2023-07-11 9:11 [PATCH 1/3] soc: kvx: Rename function to match global variable Jules Maselbas
2023-07-11 9:11 ` [PATCH 2/3] soc: kvx: Fix memory leaks Jules Maselbas
2023-07-11 9:11 ` [PATCH 3/3] soc: kvx: Add board_sn global var from OTP Jules Maselbas
@ 2023-07-26 12:18 ` Sascha Hauer
2 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2023-07-26 12:18 UTC (permalink / raw)
To: Jules Maselbas; +Cc: barebox
On Tue, Jul 11, 2023 at 11:11:21AM +0200, Jules Maselbas wrote:
> The global variable "kvx_serial" has been renamed to "kvx_mppa_id".
> Do the same with the function name that sets this global variable.
>
> Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
> ---
> drivers/soc/kvx/kvx_socinfo.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/soc/kvx/kvx_socinfo.c b/drivers/soc/kvx/kvx_socinfo.c
> index 8cac8899d2..fc7ba1c1b9 100644
> --- a/drivers/soc/kvx/kvx_socinfo.c
> +++ b/drivers/soc/kvx/kvx_socinfo.c
> @@ -81,7 +81,7 @@ static int base38_decode(char *s, u64 val, int nb_char)
> return 0;
> }
>
> -static int kvx_read_serial(struct device_node *socinfo)
> +static int kvx_read_mppa_id(struct device_node *socinfo)
This renames the function, but not the caller.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 6+ messages in thread