mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: John Watts <contact@jookia.org>
To: Marco Felsch <m.felsch@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v2 3/4] ARM: novena: Read Ethernet MAC address from EEPROM
Date: Thu, 26 Jan 2023 19:05:54 +1100	[thread overview]
Message-ID: <Y9I0YqYY2ocvAsmk@novena-choice-citizen> (raw)
In-Reply-To: <20230125200714.cxpg572weivxjeam@pengutronix.de>

On Wed, Jan 25, 2023 at 09:07:14PM +0100, Marco Felsch wrote:
> > +	rc = read_file_2("/dev/eeprom0", &read, &eeprom, max);
> 
> You never free the eeprom buffer.

Argh, I explicitly remember writing down that I need to do this then promptly
got distracted when searching for the correct free function to use.

> > +
> > +	if (rc < 0 && rc != -EFBIG) {
> > +		pr_err("Unable to read Novena EEPROM: %s\n", strerror(-rc));
> > +		return NULL;
> > +	} else if (read != max) {
> > +		pr_err("Short read from Novena EEPROM?\n");
> > +		return NULL;
> > +	} else {
> > +		return eeprom;
> > +	}
> 
> Last else can be dropped and instad:
> 
> 	return eeprom;
> > +}

Okay.

> > +
> > +static bool novena_check_eeprom(struct novena_eeprom *eeprom)
> > +{
> > +	char *sig = eeprom->signature;
> > +	size_t size = sizeof(eeprom->signature);
> > +
> > +	if (memcmp("Novena", sig, size) != 0) {
> > +		pr_err("Unknown Novena EEPROM signature\n");
> > +		return false;
> > +	}
> > +
> > +	return true;
> > +}
> > +
> > +static void novena_set_mac(struct novena_eeprom *eeprom)
> > +{
> > +	struct device_node *dnode;
> > +
> > +	dnode = of_find_node_by_alias(of_get_root_node(), "ethernet0");
> > +	if (dnode)
> > +		of_eth_register_ethaddr(dnode, eeprom->mac);
> > +	else
> > +		pr_err("Unable to find ethernet node\n");
> > +}
> > +
> > +static void novena_try_eeprom(void)
> > +{
> > +	struct novena_eeprom *eeprom = novena_read_eeprom();
> > +
> > +	if (!eeprom || !novena_check_eeprom(eeprom))
> > +		return;
> > +
> > +	novena_set_mac(eeprom);
> > +}
> >  
> >  static int novena_probe(struct device *dev)
> >  {
> > +	novena_try_eeprom();
> 
> It's not wrong to move it into a sub-function but IMO at least this
> function can be part of the probe() function. Also I would do the
> device_ensured_probe function here and just have one function which I
> would call: novena_set_mac(). This way it's a bit easier to follow the
> code. But that's just my oppinion.

I'm not quite sure what you mean, could you provide an example?

> > +	eeprom: eeprom@56 {
> > +		compatible = "24c512";
> > +		reg = <0x56>;
> > +		pagesize = <128>;
> > +		status = "okay";
> 
> status can be dropped, "okay" is the default for the dtc.

Gotcha.

> 
> Regards,
>   Marco

John.



  reply	other threads:[~2023-01-26  8:08 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-22 17:51 [PATCH 0/5] Add support for the Kosagi Novena board John Watts
2023-01-22 17:51 ` [PATCH 1/5] ARM: novena: Add " John Watts
2023-01-23  9:20   ` Sascha Hauer
2023-01-22 17:51 ` [PATCH 2/5] ARM: novena: Setup RAM using static configuration John Watts
2023-01-22 17:51 ` [PATCH 3/5] ARM: novena: Require the PFUZE regulator John Watts
2023-01-22 17:51 ` [PATCH 4/5] ARM: novena: Read Ethernet MAC address from EEPROM John Watts
2023-01-23  9:33   ` Sascha Hauer
2023-01-23  9:55     ` John Watts
2023-01-24 18:35     ` John Watts
2023-01-25  8:04       ` Sascha Hauer
2023-01-25  8:11         ` John Watts
2023-01-25  8:19           ` Sascha Hauer
2023-01-25 13:31             ` John Watts
2023-01-25 13:48               ` Ahmad Fatoum
2023-01-25 14:04                 ` John Watts
2023-01-25 14:16                   ` Ahmad Fatoum
2023-01-25 14:28                     ` John Watts
2023-01-25 14:33                       ` Ahmad Fatoum
2023-01-25 14:50                         ` John Watts
2023-01-25 15:42               ` Sascha Hauer
2023-01-25 16:13                 ` John Watts
2023-01-22 17:51 ` [PATCH 5/5] ARM: novena: Use DDR3 information from SPD EEPROM John Watts
2023-01-22 23:20   ` John Watts
2023-01-25 16:42 ` [PATCH v2 0/4] Add support for the Kosagi Novena board John Watts
2023-01-25 16:42 ` [PATCH v2 1/4] ARM: novena: Add " John Watts
2023-01-25 19:33   ` Marco Felsch
2023-01-26  7:25     ` Sascha Hauer
2023-01-26  7:50     ` John Watts
2023-01-26  9:13       ` Marco Felsch
2023-01-25 16:42 ` [PATCH v2 2/4] ARM: novena: Setup RAM using static configuration John Watts
2023-01-25 19:39   ` Marco Felsch
2023-01-26  7:54     ` John Watts
2023-01-26  8:11       ` Sascha Hauer
2023-01-26  9:14         ` Marco Felsch
2023-01-25 16:42 ` [PATCH v2 3/4] ARM: novena: Read Ethernet MAC address from EEPROM John Watts
2023-01-25 20:07   ` Marco Felsch
2023-01-26  8:05     ` John Watts [this message]
2023-01-26  9:07       ` Marco Felsch
2023-01-25 16:42 ` [PATCH v2 4/4] ARM: novena: Use DDR3 information from SPD EEPROM John Watts
2023-01-29 23:27 ` [PATCH v3 0/4] Add support for the Kosagi Novena board John Watts
2023-01-29 23:27 ` [PATCH v3 1/4] ARM: novena: Add " John Watts
2023-01-30 20:13   ` Marco Felsch
2023-01-30 20:26     ` John Watts
2023-01-31  9:45       ` Marco Felsch
2023-01-29 23:27 ` [PATCH v3 2/4] ARM: novena: Setup RAM using static configuration John Watts
2023-01-29 23:27 ` [PATCH v3 3/4] ARM: novena: Read Ethernet MAC address from EEPROM John Watts
2023-01-30 20:04   ` Marco Felsch
2023-01-30 20:25     ` John Watts
2023-01-31  9:29       ` Marco Felsch
2023-01-29 23:28 ` [PATCH v3 4/4] ARM: novena: Use DDR3 information from SPD EEPROM John Watts
2023-01-30 20:18   ` Marco Felsch
2023-01-30 20:41     ` John Watts

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y9I0YqYY2ocvAsmk@novena-choice-citizen \
    --to=contact@jookia.org \
    --cc=barebox@lists.infradead.org \
    --cc=m.felsch@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox