From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master] net: tap: return -ENODEV when TAP permission is denied
Date: Thu, 12 Dec 2024 08:22:28 +0100 [thread overview]
Message-ID: <20241212072228.2468741-1-a.fatoum@pengutronix.de> (raw)
tap_alloc will return -EPERM, when not running with CAP_NET_ADMIN.
For most users, this is the default case and thus barebox printing:
could not get tap device: Operation not permitted
ERROR: tap tap0: probe failed: Operation not permitted
is just confusing. Improve this by returning -ENODEV in that situation
instead, which driver core already understands to be an acceptable
return code that warrants no error message.
The user will then be shown only the first message with no scary red
ERROR prefix.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/net/tap.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index 8bc52b1e154b..aa96f02bfc7c 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -61,16 +61,18 @@ static int tap_probe(struct device *dev)
{
struct eth_device *edev;
struct tap_priv *priv;
- int ret = 0;
+ int ret;
priv = xzalloc(sizeof(struct tap_priv));
priv->name = "barebox";
- priv->fd = tap_alloc(priv->name);
- if (priv->fd < 0) {
- ret = priv->fd;
+ ret = tap_alloc(priv->name);
+ if (ret == -EPERM)
+ ret = -ENODEV;
+ if (ret < 0)
goto out;
- }
+
+ priv->fd = ret;
priv->rx_buf = xmalloc(PKTSIZE);
--
2.39.5
next reply other threads:[~2024-12-12 7:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-12 7:22 Ahmad Fatoum [this message]
2024-12-12 8:18 ` Sascha Hauer
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=20241212072228.2468741-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--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