* [PATCH master] net: tap: return -ENODEV when TAP permission is denied
@ 2024-12-12 7:22 Ahmad Fatoum
2024-12-12 8:18 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2024-12-12 7:22 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH master] net: tap: return -ENODEV when TAP permission is denied
2024-12-12 7:22 [PATCH master] net: tap: return -ENODEV when TAP permission is denied Ahmad Fatoum
@ 2024-12-12 8:18 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2024-12-12 8:18 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Thu, 12 Dec 2024 08:22:28 +0100, Ahmad Fatoum wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] net: tap: return -ENODEV when TAP permission is denied
https://git.pengutronix.de/cgit/barebox/commit/?id=7ddffa986081 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-12-12 8:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-12 7:22 [PATCH master] net: tap: return -ENODEV when TAP permission is denied Ahmad Fatoum
2024-12-12 8:18 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox