public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Ben Hutchings <bhutchings@solarflare.com>
To: Jiri Pirko <jpirko@redhat.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net,
	eric.dumazet@gmail.com, shemminger@vyatta.com
Subject: Re: [patch net-next-2.6 1/2] net: allow to change carrier via sysfs
Date: Tue, 30 Aug 2011 16:14:22 +0100	[thread overview]
Message-ID: <1314717262.2752.11.camel@bwh-desktop> (raw)
In-Reply-To: <1314715608-978-2-git-send-email-jpirko@redhat.com>

On Tue, 2011-08-30 at 16:46 +0200, Jiri Pirko wrote:
> Allow to write to "carrier" attribute. Devices may implement ndo_change_carrier
> callback to allow changing carrier from userspace.
[...]
> diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
> index 56e42ab..c8f2ca4 100644
> --- a/net/core/net-sysfs.c
> +++ b/net/core/net-sysfs.c
> @@ -126,6 +126,30 @@ static ssize_t show_broadcast(struct device *dev,
>  	return -EINVAL;
>  }
>  
> +static ssize_t store_carrier(struct device *dev, struct device_attribute *attr,
> +			     const char *buf, size_t len)
> +{
> +	struct net_device *netdev = to_net_dev(dev);
> +	ssize_t ret;
> +	int new_value;
> +
> +	if (!capable(CAP_NET_ADMIN))
> +		return -EPERM;
> +
> +	if (!netif_running(netdev))
> +		return -EINVAL;

Not sure that's the right error code.

> +	if (sscanf(buf, "%d", &new_value) != 1)
> +		return -EINVAL;

kstrtoint()

(Or maybe we should have kstrobool().)

> +	if (!rtnl_trylock())
> +		return restart_syscall();
[...]

This is consistent with other attributes, but it seems like a really bad
practice as it will generally result in the process busy-waiting on the
RTNL lock!  I think it would be better to add and use an
rtnl_lock_interruptible().

Ben.

-- 
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.

  reply	other threads:[~2011-08-30 15:14 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-30 14:46 [patch net-next-2.6 0/2] net: allow to change carrier via sysfs Jiri Pirko
2011-08-30 14:46 ` [patch net-next-2.6 1/2] " Jiri Pirko
2011-08-30 15:14   ` Ben Hutchings [this message]
2011-08-30 15:19     ` Jiri Pirko
2011-08-30 18:11   ` Michał Mirosław
2011-08-30 18:25     ` Stephen Hemminger
2011-08-31  8:31       ` Jiri Pirko
2011-08-31  8:26     ` Jiri Pirko
2011-08-31  8:33       ` Michał Mirosław
2011-08-31  8:45         ` Jiri Pirko
2011-08-31 20:03           ` Nicolas de Pesloüan
2011-08-31 20:12             ` Ben Hutchings
2011-08-31 20:26               ` Jiri Pirko
2011-08-31 20:31               ` Nicolas de Pesloüan
2011-08-31 20:44                 ` Ben Hutchings
2011-08-31 20:48                 ` Ben Greear
2011-08-31 21:36                   ` Ben Hutchings
2011-08-31 21:40                     ` Stephen Hemminger
2011-09-01  5:46                       ` Jiri Pirko
2011-08-31 21:49                     ` Ben Greear
2011-09-01  5:44                   ` Jiri Pirko
2011-08-30 14:46 ` [patch net-next-2.6 2/2] dummy: implement carrier change Jiri Pirko

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=1314717262.2752.11.camel@bwh-desktop \
    --to=bhutchings@solarflare.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=jpirko@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@vyatta.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox