From: Simon Horman <horms@kernel.org>
To: Bhavya Kapoor <b-kapoor@ti.com>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
linux-can@vger.kernel.org, mailhol.vincent@wanadoo.fr,
rcsekar@samsung.com, pabeni@redhat.com, kuba@kernel.org,
edumazet@google.com, davem@davemloft.net, mkl@pengutronix.de,
wg@grandegger.com, vigneshr@ti.com, u-kumar1@ti.com
Subject: Re: [PATCH] net: can: Add support for aliases in CAN
Date: Thu, 4 Jan 2024 17:19:40 +0000 [thread overview]
Message-ID: <20240104171940.GI31813@kernel.org> (raw)
In-Reply-To: <20240102102949.138607-1-b-kapoor@ti.com>
On Tue, Jan 02, 2024 at 03:59:49PM +0530, Bhavya Kapoor wrote:
> When multiple CAN's are present, then names that are getting assigned
> changes after every boot even after providing alias in the device tree.
> Thus, Add support for implementing CAN aliasing so that names or
> alias for CAN will now be provided from device tree.
>
> Signed-off-by: Bhavya Kapoor <b-kapoor@ti.com>
Hi Bhavya,
some minor feedback from my side.
...
> diff --git a/drivers/net/can/dev/dev.c b/drivers/net/can/dev/dev.c
> index 3a3be5cdfc1f..ed483c23ec79 100644
> --- a/drivers/net/can/dev/dev.c
> +++ b/drivers/net/can/dev/dev.c
> @@ -247,12 +247,14 @@ void can_setup(struct net_device *dev)
>
> /* Allocate and setup space for the CAN network device */
> struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
> - unsigned int txqs, unsigned int rxqs)
> + unsigned int txqs, unsigned int rxqs,
> + struct device *candev)
> {
> struct can_ml_priv *can_ml;
> struct net_device *dev;
> struct can_priv *priv;
> - int size;
> + int size, aliasid;
> + char devname[6] = "can%d";
nit: Please consider arranging local variables in Networking code
in reverse xmas tree order - longest line to shortest.
>
> /* We put the driver's priv, the CAN mid layer priv and the
> * echo skb into the netdevice's priv. The memory layout for
> @@ -273,7 +275,14 @@ struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
> size = ALIGN(size, sizeof(struct sk_buff *)) +
> echo_skb_max * sizeof(struct sk_buff *);
>
> - dev = alloc_netdev_mqs(size, "can%d", NET_NAME_UNKNOWN, can_setup,
> + if (candev) {
> + aliasid = of_alias_get_id(candev->of_node, "can");
> + if (aliasid >= 0)
> + snprintf(devname, sizeof(devname), "%s%d", "can", aliasid);
The size of devname is 6 bytes (can%d\0).
This means that snprintf() will truncate devname if alias is greater than 99.
Is this a concern?
If so, perhaps devname could be declared to be IFNAMSIZ bytes long?
Flagged by gcc-13 -Wformat-truncation
> + }
> + dev_dbg(candev, "Name of CAN assigned is : %s\n", devname);
> +
> + dev = alloc_netdev_mqs(size, devname, NET_NAME_UNKNOWN, can_setup,
> txqs, rxqs);
> if (!dev)
> return NULL;
...
next prev parent reply other threads:[~2024-01-04 17:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-02 10:29 [PATCH] net: can: Add support for aliases in CAN Bhavya Kapoor
2024-01-02 11:13 ` Marc Kleine-Budde
2024-01-12 15:23 ` Kumar, Udit
2024-01-12 15:43 ` Marc Kleine-Budde
2024-01-04 17:19 ` Simon Horman [this message]
2024-01-05 7:19 ` Bhavya Kapoor
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=20240104171940.GI31813@kernel.org \
--to=horms@kernel.org \
--cc=b-kapoor@ti.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mailhol.vincent@wanadoo.fr \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rcsekar@samsung.com \
--cc=u-kumar1@ti.com \
--cc=vigneshr@ti.com \
--cc=wg@grandegger.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.