mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: "Baeuerle, Florian" <Florian.Baeuerle@allegion.com>
Cc: "barebox@lists.infradead.org" <barebox@lists.infradead.org>
Subject: Re: [PATCH] commands/of_property: add option to apply changes as fixup
Date: Fri, 25 May 2018 09:11:57 +0200	[thread overview]
Message-ID: <20180525071156.txqmmif6qbqn4hnm@pengutronix.de> (raw)
In-Reply-To: <264898e761473a90c2be407c7c0e9ae656bb39bf.camel@allegion.com>

HI Florian,

looks good generally. Some small comments below.

On Thu, May 24, 2018 at 02:48:47PM +0000, Baeuerle, Florian wrote:
> +static int of_fixup_property_set(struct device_node *root, void *context)
> +{
> +	const struct of_fixup_property_data *fixup = context;
> +	int ret = do_of_property_set_now(root, fixup->path, fixup->propname,
> +			fixup->data, fixup->len);
> +
> +	free(fixup->path);
> +	free(fixup->propname);
> +	free(fixup->data);

Don't free here. A fixup can be called multiple times.

> +
> +	return ret;
> +}
> +
> +static int of_fixup_property_delete(struct device_node *root, void *context)
> +{
> +	const struct of_fixup_property_data *fixup = context;
> +	int ret = do_of_property_delete_now(root, fixup->path, fixup->propname);
> +
> +	free(fixup->path);
> +	free(fixup->propname);

ditto.

> +
> +	return ret;
> +}
> +
> +static int do_of_property_set_fixup(const char *path, const char *propname,
> +		void *data, int len)
> +{
> +	struct of_fixup_property_data *fixup;
> +	int ret = -ENOMEM;
> +
> +	fixup = xzalloc(sizeof(*fixup));
> +	if (!fixup)
> +		goto out_fixup;

The 'x' versions of the alloc functions always return successfully, no
need to check.

> +static int do_of_property_set_now(struct device_node *root, const char *path,
> +		const char *propname, void *data, int len)
> +{
> +	struct device_node *node = of_find_node_by_path_or_alias(root, path);
> +	struct property *pp = NULL;

No need to initialize.

> +
> +	if (!node) {
> +		printf("Cannot find nodepath %s\n", path);
> +		return -ENOENT;
> +	}
> +
> +	pp = of_find_property(node, propname, NULL);
> +
> +	if (pp) {
> +		free(pp->value);
> +		pp->value_const = NULL;
> +
> +		/* limit property data to the actual size */
> +		if (len)
> +			pp->value = xrealloc(data, len);
> +		else
> +			pp->value = NULL;
> +
> +		pp->length = len;
> +	} else {
> +		pp = of_new_property(node, propname, data, len);
> +		if (!pp) {
> +			printf("Cannot create property %s\n", propname);
> +			return -ENOMEM;
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +static int do_of_property_delete_now(struct device_node *root, const char *path,
> +		const char *propname)
> +{
> +	struct device_node *node = of_find_node_by_path_or_alias(root, path);
> +	struct property *pp = NULL;

ditto.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2018-05-25  7:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-24 14:48 Baeuerle, Florian
2018-05-25  7:11 ` Sascha Hauer [this message]
2018-05-25  8:23   ` Baeuerle, Florian
2018-05-25  8:39     ` s.hauer
2018-05-25  8:06 ` Baeuerle, Florian

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=20180525071156.txqmmif6qbqn4hnm@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=Florian.Baeuerle@allegion.com \
    --cc=barebox@lists.infradead.org \
    /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