All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Yajun Deng <yajun.deng@linux.dev>
Cc: davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
	horms@kernel.org, andrew+netdev@lunn.ch, netdev@vger.kernel.org
Subject: Re: [PATCH net-next] net: sysfs: Implement is_visible for phys_(port_id, port_name, switch_id)
Date: Fri, 16 May 2025 15:26:11 -0700	[thread overview]
Message-ID: <20250516152611.5945afae@kernel.org> (raw)
In-Reply-To: <20250515130205.3274-1-yajun.deng@linux.dev>

On Thu, 15 May 2025 21:02:05 +0800 Yajun Deng wrote:
> +static struct attribute *netdev_phys_attrs[] __ro_after_init = {

Why __ro_after_init and not const? I can't find the reason with 
a quick grep. This is just an array of pointers, not objects.

> +	&dev_attr_phys_port_id.attr,
> +	&dev_attr_phys_port_name.attr,
> +	&dev_attr_phys_switch_id.attr,
> +	NULL,
> +};
> +
> +static umode_t netdev_phys_is_visible(struct kobject *kobj,
> +				      struct attribute *attr, int index)
> +{
> +	struct device *dev = kobj_to_dev(kobj);
> +	struct net_device *netdev = to_net_dev(dev);
> +
> +	if (attr == &dev_attr_phys_port_id.attr) {
> +		/* The check is also done in dev_get_phys_port_id; this helps returning
> +		 * early without hitting the locking section below.
> +		 */
> +		if (!netdev->netdev_ops->ndo_get_phys_port_id)
> +			return 0;
> +	} else if (attr == &dev_attr_phys_port_name.attr) {
> +		/* The checks are also done in dev_get_phys_port_name; this helps
> +		 * returning early without hitting the locking section below.
> +		 */
> +		if (!netdev->netdev_ops->ndo_get_phys_port_name &&
> +		    !netdev->devlink_port)
> +			return 0;
> +	} else if (attr == &dev_attr_phys_switch_id.attr) {
> +		/* The checks are also done in dev_get_phys_port_name; this helps
> +		 * returning early without hitting the locking section below. This works
> +		 * because recurse is false when calling dev_get_port_parent_id.
> +		 */
> +		if (!netdev->netdev_ops->ndo_get_port_parent_id &&
> +		    !netdev->devlink_port)
> +			return 0;

I'm slightly worried some user space depends on the files existing,
but maybe ENOENT vs EOPNOTSUPP doesn't make a big difference.

Can you remove the comments, tho? I don't think they add much value.
-- 
pw-bot: cr

  reply	other threads:[~2025-05-16 22:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-15 13:02 [PATCH net-next] net: sysfs: Implement is_visible for phys_(port_id, port_name, switch_id) Yajun Deng
2025-05-16 22:26 ` Jakub Kicinski [this message]
2025-05-17  2:24   ` Yajun Deng

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=20250516152611.5945afae@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=yajun.deng@linux.dev \
    /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.