All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Lizhi Hou <lizhi.hou@amd.com>
Cc: linux-pci@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, robh@kernel.org, max.zhen@amd.com,
	sonal.santan@amd.com, stefano.stabellini@xilinx.com,
	"Clément Léger" <clement.leger@bootlin.com>
Subject: Re: [PATCH V13 1/5] of: dynamic: Add interfaces for creating device node dynamically
Date: Mon, 11 Sep 2023 23:48:13 +0300	[thread overview]
Message-ID: <ZP99DdtruXfI6L/L@smile.fi.intel.com> (raw)
In-Reply-To: <1692120000-46900-2-git-send-email-lizhi.hou@amd.com>

On Tue, Aug 15, 2023 at 10:19:56AM -0700, Lizhi Hou wrote:
> of_changeset_create_node() creates device node dynamically and attaches
> the newly created node to a changeset.
> 
> Expand of_changeset APIs to handle specific types of properties.
>     of_changeset_add_prop_string()
>     of_changeset_add_prop_string_array()
>     of_changeset_add_prop_u32_array()

...

> +/**
> + * of_changeset_add_prop_string - Add a string property to a changeset
> + *
> + * @ocs:	changeset pointer
> + * @np:		device node pointer
> + * @prop_name:	name of the property to be added
> + * @str:	pointer to null terminated string
> + *
> + * Create a string property and add it to a changeset.
> + *
> + * Return: 0 on success, a negative error value in case of an error.
> + */
> +int of_changeset_add_prop_string(struct of_changeset *ocs,
> +				 struct device_node *np,
> +				 const char *prop_name, const char *str)
> +{
> +	struct property prop;
> +
> +	prop.name = (char *)prop_name;

This looks not nice. You dropped const qualifier, which is a bit worrying.
Can  you fix underneath APIs/data types so we can avoid this?

> +	prop.length = strlen(str) + 1;

> +	prop.value = (void *)str;

Do you need this casting?

Okay, seems also related to the const qualifier. I would accept this in a form
of const void *, but it will probably look a bit weird. What about to have a value
to be a union?

> +	return of_changeset_add_prop_helper(ocs, np, &prop);
> +}

...

> +	prop.name = (char *)prop_name;

Same comment as per above.

...

> +	prop.length = 0;
> +	for (i = 0; i < sz; i++)
> +		prop.length += strlen(str_array[i]) + 1;
> +
> +	prop.value = kmalloc(prop.length, GFP_KERNEL);
> +	if (!prop.value)
> +		return -ENOMEM;
> +
> +	vp = prop.value;
> +	for (i = 0; i < sz; i++) {
> +		vp += snprintf(vp, (char *)prop.value + prop.length - vp, "%s",
> +			       str_array[i]) + 1;
> +	}

Is all this kinda of reinventing kasprintf()? Perhaps you can somehow utilize
kasprintf_strarray()? It might require to get a common denominator that takes
a formatting string as a parameter.

> +	ret = of_changeset_add_prop_helper(ocs, np, &prop);
> +	kfree(prop.value);

...

> +	for (i = 0; i < sz; i++)
> +		val[i] = cpu_to_be32(array[i]);

NIH cpu_to_be32_array()

...

> +	prop.name = (char *)prop_name;
> +	prop.length = sizeof(u32) * sz;
> +	prop.value = (void *)val;

Do you need this casting?

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2023-09-11 22:47 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-15 17:19 [PATCH V13 0/5] Generate device tree node for pci devices Lizhi Hou
2023-08-15 17:19 ` [PATCH V13 1/5] of: dynamic: Add interfaces for creating device node dynamically Lizhi Hou
2023-09-11 20:48   ` Andy Shevchenko [this message]
2023-08-15 17:19 ` [PATCH V13 2/5] PCI: Create device tree node for bridge Lizhi Hou
2023-08-31 13:57   ` Guenter Roeck
2023-09-11 14:48   ` Jonathan Cameron
2023-09-11 15:35     ` Herve Codina
2023-09-11 15:47       ` Jonathan Cameron
2023-09-11 16:22         ` Jonathan Cameron
2023-09-11 21:13           ` Andy Shevchenko
2023-09-11 16:58     ` Lizhi Hou
2023-09-12 10:10       ` Jonathan Cameron
2023-09-12 17:05         ` Lizhi Hou
2023-09-11 15:13   ` Herve Codina
2023-09-11 17:53     ` Lizhi Hou
2023-09-11 21:06   ` Andy Shevchenko
2023-08-15 17:19 ` [PATCH V13 3/5] PCI: Add quirks to generate device tree node for Xilinx Alveo U50 Lizhi Hou
2023-08-15 17:19 ` [PATCH V13 4/5] of: overlay: Extend of_overlay_fdt_apply() to specify the target node Lizhi Hou
2023-08-24  8:31   ` Geert Uytterhoeven
2023-08-24 18:40     ` Lizhi Hou
2023-08-24 21:01       ` Rob Herring
2023-08-25  7:25       ` Geert Uytterhoeven
2023-08-28 17:12         ` Lizhi Hou
2023-08-15 17:20 ` [PATCH V13 5/5] of: unittest: Add pci_dt_testdrv pci driver Lizhi Hou
2023-09-11 20:37 ` [PATCH V13 0/5] Generate device tree node for pci devices Andy Shevchenko
2023-09-12 19:12   ` Rob Herring
2023-09-13 11:17     ` Andy Shevchenko
2023-09-15 17:30       ` Herve Codina
2023-09-18  7:17         ` Andy Shevchenko
2023-09-18 10:54           ` Jonathan Cameron
2023-09-21 12:20           ` Rob Herring
2023-09-21 13:26             ` Herve Codina
2023-09-11 21:08 ` Andy Shevchenko

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=ZP99DdtruXfI6L/L@smile.fi.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=clement.leger@bootlin.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lizhi.hou@amd.com \
    --cc=max.zhen@amd.com \
    --cc=robh@kernel.org \
    --cc=sonal.santan@amd.com \
    --cc=stefano.stabellini@xilinx.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.