[PATCH master] net: tap: return -ENODEV when TAP permission is denied
Ahmad Fatoum
a.fatoum at pengutronix.de
Wed Dec 11 23:22:28 PST 2024
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 at 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
More information about the barebox
mailing list