]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: ethtool: pass genl_info to the ethnl parse_request operation
authorMaxime Chevallier <maxime.chevallier@bootlin.com>
Mon, 23 Mar 2026 09:58:32 +0000 (10:58 +0100)
committerJakub Kicinski <kuba@kernel.org>
Wed, 25 Mar 2026 03:14:29 +0000 (20:14 -0700)
The .parse_request() ethnl operation extracts the relevant attributes
from the netlink request to populate the private req_info.

By passing genl_info as a parameter to this callback, we can use
the GENL_REQ_ATTR_CHECK() macro to check for missing mandatory
parameters.

This macro has the advantage of returning a better error explanation
through the netlink_ext_ack struct.

Convert the eeprom ethnl code to this macro, as it's the only command
yet that has mandatory request parameters.

Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Link: https://patch.msgid.link/20260323095833.136266-1-maxime.chevallier@bootlin.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ethtool/eeprom.c
net/ethtool/netlink.c
net/ethtool/netlink.h
net/ethtool/pause.c
net/ethtool/rss.c
net/ethtool/stats.c
net/ethtool/strset.c
net/ethtool/tsinfo.c

index caf1e41e676b5319975ac87adb592f4c675ea620..a557e3996c851daed4f75d38f434047c9697c1b5 100644 (file)
@@ -150,15 +150,17 @@ err_free:
        return ret;
 }
 
-static int eeprom_parse_request(struct ethnl_req_info *req_info, struct nlattr **tb,
+static int eeprom_parse_request(struct ethnl_req_info *req_info,
+                               const struct genl_info *info,
+                               struct nlattr **tb,
                                struct netlink_ext_ack *extack)
 {
        struct eeprom_req_info *request = MODULE_EEPROM_REQINFO(req_info);
 
-       if (!tb[ETHTOOL_A_MODULE_EEPROM_OFFSET] ||
-           !tb[ETHTOOL_A_MODULE_EEPROM_LENGTH] ||
-           !tb[ETHTOOL_A_MODULE_EEPROM_PAGE] ||
-           !tb[ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS])
+       if (GENL_REQ_ATTR_CHECK(info, ETHTOOL_A_MODULE_EEPROM_OFFSET) ||
+           GENL_REQ_ATTR_CHECK(info, ETHTOOL_A_MODULE_EEPROM_LENGTH) ||
+           GENL_REQ_ATTR_CHECK(info, ETHTOOL_A_MODULE_EEPROM_PAGE) ||
+           GENL_REQ_ATTR_CHECK(info, ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS))
                return -EINVAL;
 
        request->i2c_address = nla_get_u8(tb[ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS]);
index 14cb06ec5171d6df90d9f792338232d09a59a812..5046023a30b10089ba33c80106c95248e9829853 100644 (file)
@@ -462,7 +462,8 @@ static int ethnl_default_parse(struct ethnl_req_info *req_info,
                return ret;
 
        if (request_ops->parse_request) {
-               ret = request_ops->parse_request(req_info, tb, info->extack);
+               ret = request_ops->parse_request(req_info, info, tb,
+                                                info->extack);
                if (ret < 0)
                        goto err_dev;
        }
index 89010eaa67dfcd7279c16689d40d3c2c468722cc..aaf6f246876832a8be9c82412c7fd202ba3009cb 100644 (file)
@@ -396,6 +396,7 @@ struct ethnl_request_ops {
        u8                      set_ntf_cmd;
 
        int (*parse_request)(struct ethnl_req_info *req_info,
+                            const struct genl_info *info,
                             struct nlattr **tb,
                             struct netlink_ext_ack *extack);
        int (*prepare_data)(const struct ethnl_req_info *req_info,
index 29f812e935b6fc3fa00359bdb4adee574aee20db..ccaec8e878b2b6cf59dc9d8a180b02e1ba6d2a7a 100644 (file)
@@ -28,6 +28,7 @@ const struct nla_policy ethnl_pause_get_policy[] = {
 };
 
 static int pause_parse_request(struct ethnl_req_info *req_base,
+                              const struct genl_info *info,
                               struct nlattr **tb,
                               struct netlink_ext_ack *extack)
 {
index 5cf90d73e70bb33d306317d588b080c9b692c53c..353110b862ab1398699c19daf16082ee743505b1 100644 (file)
@@ -66,7 +66,9 @@ const struct nla_policy ethnl_rss_get_policy[] = {
 };
 
 static int
-rss_parse_request(struct ethnl_req_info *req_info, struct nlattr **tb,
+rss_parse_request(struct ethnl_req_info *req_info,
+                 const struct genl_info *info,
+                 struct nlattr **tb,
                  struct netlink_ext_ack *extack)
 {
        struct rss_req_info *request = RSS_REQINFO(req_info);
index 38136f19b2eca7cf8d703bbb64851f7b4c325d30..9b0d8cb07675cfed9faaa1f705c6e6e91c804e5d 100644 (file)
@@ -99,6 +99,7 @@ const struct nla_policy ethnl_stats_get_policy[ETHTOOL_A_STATS_SRC + 1] = {
 };
 
 static int stats_parse_request(struct ethnl_req_info *req_base,
+                              const struct genl_info *info,
                               struct nlattr **tb,
                               struct netlink_ext_ack *extack)
 {
index aa1e50c98f3480e8cb883adf07a5bb5548d50aa2..9271aba8255edf990b866e146a9ac5e43c33c51f 100644 (file)
@@ -190,6 +190,7 @@ static const struct nla_policy strset_stringsets_policy[] = {
 };
 
 static int strset_parse_request(struct ethnl_req_info *req_base,
+                               const struct genl_info *info,
                                struct nlattr **tb,
                                struct netlink_ext_ack *extack)
 {
index 9aad62695dfb3493419c23d40fd6e33d5360f977..a865f0fdd26b1b3a92fb92c0c91ddfec47854a29 100644 (file)
@@ -70,7 +70,9 @@ int ts_parse_hwtst_provider(const struct nlattr *nest,
 }
 
 static int
-tsinfo_parse_request(struct ethnl_req_info *req_base, struct nlattr **tb,
+tsinfo_parse_request(struct ethnl_req_info *req_base,
+                    const struct genl_info *info,
+                    struct nlattr **tb,
                     struct netlink_ext_ack *extack)
 {
        struct tsinfo_req_info *req = TSINFO_REQINFO(req_base);