2022-12-02 09:12:52

by Dan Carpenter

[permalink] [raw]
Subject: net/mptcp/pm_netlink.c:1169 mptcp_pm_parse_pm_addr_attr() warn: missing error code? 'err'

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: a4412fdd49dc011bcc2c0d81ac4cab7457092650
commit: 982f17ba1a2534b878fbcb1a5273bfbc551c5397 mptcp: netlink: split mptcp_pm_parse_addr into two functions
config: i386-randconfig-m021
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>

smatch warnings:
net/mptcp/pm_netlink.c:1169 mptcp_pm_parse_pm_addr_attr() warn: missing error code? 'err'

vim +/err +1169 net/mptcp/pm_netlink.c

982f17ba1a2534 Florian Westphal 2022-05-03 1145 static int mptcp_pm_parse_pm_addr_attr(struct nlattr *tb[],
982f17ba1a2534 Florian Westphal 2022-05-03 1146 const struct nlattr *attr,
982f17ba1a2534 Florian Westphal 2022-05-03 1147 struct genl_info *info,
982f17ba1a2534 Florian Westphal 2022-05-03 1148 struct mptcp_addr_info *addr,
982f17ba1a2534 Florian Westphal 2022-05-03 1149 bool require_family)
01cacb00b35cb6 Paolo Abeni 2020-03-27 1150 {
01cacb00b35cb6 Paolo Abeni 2020-03-27 1151 int err, addr_addr;
01cacb00b35cb6 Paolo Abeni 2020-03-27 1152
01cacb00b35cb6 Paolo Abeni 2020-03-27 1153 if (!attr) {
01cacb00b35cb6 Paolo Abeni 2020-03-27 1154 GENL_SET_ERR_MSG(info, "missing address info");
01cacb00b35cb6 Paolo Abeni 2020-03-27 1155 return -EINVAL;
01cacb00b35cb6 Paolo Abeni 2020-03-27 1156 }
01cacb00b35cb6 Paolo Abeni 2020-03-27 1157
01cacb00b35cb6 Paolo Abeni 2020-03-27 1158 /* no validation needed - was already done via nested policy */
01cacb00b35cb6 Paolo Abeni 2020-03-27 1159 err = nla_parse_nested_deprecated(tb, MPTCP_PM_ADDR_ATTR_MAX, attr,
01cacb00b35cb6 Paolo Abeni 2020-03-27 1160 mptcp_pm_addr_policy, info->extack);
01cacb00b35cb6 Paolo Abeni 2020-03-27 1161 if (err)
01cacb00b35cb6 Paolo Abeni 2020-03-27 1162 return err;
01cacb00b35cb6 Paolo Abeni 2020-03-27 1163
982f17ba1a2534 Florian Westphal 2022-05-03 1164 if (tb[MPTCP_PM_ADDR_ATTR_ID])
982f17ba1a2534 Florian Westphal 2022-05-03 1165 addr->id = nla_get_u8(tb[MPTCP_PM_ADDR_ATTR_ID]);
982f17ba1a2534 Florian Westphal 2022-05-03 1166
01cacb00b35cb6 Paolo Abeni 2020-03-27 1167 if (!tb[MPTCP_PM_ADDR_ATTR_FAMILY]) {
01cacb00b35cb6 Paolo Abeni 2020-03-27 1168 if (!require_family)
982f17ba1a2534 Florian Westphal 2022-05-03 @1169 return err;

"err" is zero at this point. Presumably a negative error code was
intended.

01cacb00b35cb6 Paolo Abeni 2020-03-27 1170
01cacb00b35cb6 Paolo Abeni 2020-03-27 1171 NL_SET_ERR_MSG_ATTR(info->extack, attr,
01cacb00b35cb6 Paolo Abeni 2020-03-27 1172 "missing family");
01cacb00b35cb6 Paolo Abeni 2020-03-27 1173 return -EINVAL;
01cacb00b35cb6 Paolo Abeni 2020-03-27 1174 }
01cacb00b35cb6 Paolo Abeni 2020-03-27 1175
982f17ba1a2534 Florian Westphal 2022-05-03 1176 addr->family = nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_FAMILY]);
982f17ba1a2534 Florian Westphal 2022-05-03 1177 if (addr->family != AF_INET
01cacb00b35cb6 Paolo Abeni 2020-03-27 1178 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
982f17ba1a2534 Florian Westphal 2022-05-03 1179 && addr->family != AF_INET6
01cacb00b35cb6 Paolo Abeni 2020-03-27 1180 #endif
01cacb00b35cb6 Paolo Abeni 2020-03-27 1181 ) {
01cacb00b35cb6 Paolo Abeni 2020-03-27 1182 NL_SET_ERR_MSG_ATTR(info->extack, attr,
01cacb00b35cb6 Paolo Abeni 2020-03-27 1183 "unknown address family");
01cacb00b35cb6 Paolo Abeni 2020-03-27 1184 return -EINVAL;
01cacb00b35cb6 Paolo Abeni 2020-03-27 1185 }
982f17ba1a2534 Florian Westphal 2022-05-03 1186 addr_addr = mptcp_pm_family_to_addr(addr->family);
01cacb00b35cb6 Paolo Abeni 2020-03-27 1187 if (!tb[addr_addr]) {
01cacb00b35cb6 Paolo Abeni 2020-03-27 1188 NL_SET_ERR_MSG_ATTR(info->extack, attr,
01cacb00b35cb6 Paolo Abeni 2020-03-27 1189 "missing address data");
01cacb00b35cb6 Paolo Abeni 2020-03-27 1190 return -EINVAL;
01cacb00b35cb6 Paolo Abeni 2020-03-27 1191 }

--
0-DAY CI Kernel Test Service
https://01.org/lkp


2022-12-02 23:46:42

by Mat Martineau

[permalink] [raw]
Subject: Re: net/mptcp/pm_netlink.c:1169 mptcp_pm_parse_pm_addr_attr() warn: missing error code? 'err'

On Fri, 2 Dec 2022, Dan Carpenter wrote:

> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: a4412fdd49dc011bcc2c0d81ac4cab7457092650
> commit: 982f17ba1a2534b878fbcb1a5273bfbc551c5397 mptcp: netlink: split mptcp_pm_parse_addr into two functions
> config: i386-randconfig-m021
> compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
>
> If you fix the issue, kindly add following tag where applicable
> | Reported-by: kernel test robot <[email protected]>
> | Reported-by: Dan Carpenter <[email protected]>
>
> smatch warnings:
> net/mptcp/pm_netlink.c:1169 mptcp_pm_parse_pm_addr_attr() warn: missing error code? 'err'
>
> vim +/err +1169 net/mptcp/pm_netlink.c
>
> 982f17ba1a2534 Florian Westphal 2022-05-03 1145 static int mptcp_pm_parse_pm_addr_attr(struct nlattr *tb[],
> 982f17ba1a2534 Florian Westphal 2022-05-03 1146 const struct nlattr *attr,
> 982f17ba1a2534 Florian Westphal 2022-05-03 1147 struct genl_info *info,
> 982f17ba1a2534 Florian Westphal 2022-05-03 1148 struct mptcp_addr_info *addr,
> 982f17ba1a2534 Florian Westphal 2022-05-03 1149 bool require_family)
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1150 {
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1151 int err, addr_addr;
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1152
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1153 if (!attr) {
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1154 GENL_SET_ERR_MSG(info, "missing address info");
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1155 return -EINVAL;
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1156 }
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1157
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1158 /* no validation needed - was already done via nested policy */
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1159 err = nla_parse_nested_deprecated(tb, MPTCP_PM_ADDR_ATTR_MAX, attr,
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1160 mptcp_pm_addr_policy, info->extack);
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1161 if (err)
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1162 return err;
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1163
> 982f17ba1a2534 Florian Westphal 2022-05-03 1164 if (tb[MPTCP_PM_ADDR_ATTR_ID])
> 982f17ba1a2534 Florian Westphal 2022-05-03 1165 addr->id = nla_get_u8(tb[MPTCP_PM_ADDR_ATTR_ID]);
> 982f17ba1a2534 Florian Westphal 2022-05-03 1166
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1167 if (!tb[MPTCP_PM_ADDR_ATTR_FAMILY]) {
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1168 if (!require_family)
> 982f17ba1a2534 Florian Westphal 2022-05-03 @1169 return err;
>
> "err" is zero at this point. Presumably a negative error code was
> intended.

Hi Dan -

The intended error code is 0 here: the return happens if no
MPTCP_PM_ADDR_ATTR_FAMILY value is present and require_family is false.

It would be clearer to "return 0;", but the code is working as expected.


Could you be sure to cc [email protected] and
[email protected] for future MPTCP issues?

Thanks,

Mat


>
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1170
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1171 NL_SET_ERR_MSG_ATTR(info->extack, attr,
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1172 "missing family");
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1173 return -EINVAL;
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1174 }
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1175
> 982f17ba1a2534 Florian Westphal 2022-05-03 1176 addr->family = nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_FAMILY]);
> 982f17ba1a2534 Florian Westphal 2022-05-03 1177 if (addr->family != AF_INET
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1178 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
> 982f17ba1a2534 Florian Westphal 2022-05-03 1179 && addr->family != AF_INET6
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1180 #endif
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1181 ) {
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1182 NL_SET_ERR_MSG_ATTR(info->extack, attr,
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1183 "unknown address family");
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1184 return -EINVAL;
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1185 }
> 982f17ba1a2534 Florian Westphal 2022-05-03 1186 addr_addr = mptcp_pm_family_to_addr(addr->family);
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1187 if (!tb[addr_addr]) {
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1188 NL_SET_ERR_MSG_ATTR(info->extack, attr,
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1189 "missing address data");
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1190 return -EINVAL;
> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1191 }
>
> --
> 0-DAY CI Kernel Test Service
> https://01.org/lkp
>
>

--
Mat Martineau
Intel

2022-12-03 08:49:02

by Dan Carpenter

[permalink] [raw]
Subject: Re: net/mptcp/pm_netlink.c:1169 mptcp_pm_parse_pm_addr_attr() warn: missing error code? 'err'

On Fri, Dec 02, 2022 at 03:38:01PM -0800, Mat Martineau wrote:
> > 01cacb00b35cb6 Paolo Abeni 2020-03-27 1158 /* no validation needed - was already done via nested policy */
> > 01cacb00b35cb6 Paolo Abeni 2020-03-27 1159 err = nla_parse_nested_deprecated(tb, MPTCP_PM_ADDR_ATTR_MAX, attr,
> > 01cacb00b35cb6 Paolo Abeni 2020-03-27 1160 mptcp_pm_addr_policy, info->extack);
> > 01cacb00b35cb6 Paolo Abeni 2020-03-27 1161 if (err)
> > 01cacb00b35cb6 Paolo Abeni 2020-03-27 1162 return err;
> > 01cacb00b35cb6 Paolo Abeni 2020-03-27 1163
> > 982f17ba1a2534 Florian Westphal 2022-05-03 1164 if (tb[MPTCP_PM_ADDR_ATTR_ID])
> > 982f17ba1a2534 Florian Westphal 2022-05-03 1165 addr->id = nla_get_u8(tb[MPTCP_PM_ADDR_ATTR_ID]);
> > 982f17ba1a2534 Florian Westphal 2022-05-03 1166
> > 01cacb00b35cb6 Paolo Abeni 2020-03-27 1167 if (!tb[MPTCP_PM_ADDR_ATTR_FAMILY]) {
> > 01cacb00b35cb6 Paolo Abeni 2020-03-27 1168 if (!require_family)
> > 982f17ba1a2534 Florian Westphal 2022-05-03 @1169 return err;
> >
> > "err" is zero at this point. Presumably a negative error code was
> > intended.
>
> Hi Dan -
>
> The intended error code is 0 here: the return happens if no
> MPTCP_PM_ADDR_ATTR_FAMILY value is present and require_family is false.
>
> It would be clearer to "return 0;", but the code is working as expected.
>
>
> Could you be sure to cc [email protected] and
> [email protected] for future MPTCP issues?

These emails are automatically generated by the kbuild team. I don't
know what kind of heuristics they use... I've put them on the To
header. There is probably a reason why they don't just use
get_maintainer.pl...

regards,
dan carpenter

2022-12-06 11:00:19

by Chen, Rong A

[permalink] [raw]
Subject: Re: net/mptcp/pm_netlink.c:1169 mptcp_pm_parse_pm_addr_attr() warn: missing error code? 'err'



On 12/3/2022 4:29 PM, Dan Carpenter wrote:
> On Fri, Dec 02, 2022 at 03:38:01PM -0800, Mat Martineau wrote:
>>> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1158 /* no validation needed - was already done via nested policy */
>>> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1159 err = nla_parse_nested_deprecated(tb, MPTCP_PM_ADDR_ATTR_MAX, attr,
>>> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1160 mptcp_pm_addr_policy, info->extack);
>>> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1161 if (err)
>>> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1162 return err;
>>> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1163
>>> 982f17ba1a2534 Florian Westphal 2022-05-03 1164 if (tb[MPTCP_PM_ADDR_ATTR_ID])
>>> 982f17ba1a2534 Florian Westphal 2022-05-03 1165 addr->id = nla_get_u8(tb[MPTCP_PM_ADDR_ATTR_ID]);
>>> 982f17ba1a2534 Florian Westphal 2022-05-03 1166
>>> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1167 if (!tb[MPTCP_PM_ADDR_ATTR_FAMILY]) {
>>> 01cacb00b35cb6 Paolo Abeni 2020-03-27 1168 if (!require_family)
>>> 982f17ba1a2534 Florian Westphal 2022-05-03 @1169 return err;
>>>
>>> "err" is zero at this point. Presumably a negative error code was
>>> intended.
>>
>> Hi Dan -
>>
>> The intended error code is 0 here: the return happens if no
>> MPTCP_PM_ADDR_ATTR_FAMILY value is present and require_family is false.
>>
>> It would be clearer to "return 0;", but the code is working as expected.
>>
>>
>> Could you be sure to cc [email protected] and
>> [email protected] for future MPTCP issues?

Hi Mat,

Sorry for the delay, we'll cc you and the mailing list in the future.

Best Regards,
Rong Chen

>
> These emails are automatically generated by the kbuild team. I don't
> know what kind of heuristics they use... I've put them on the To
> header. There is probably a reason why they don't just use
> get_maintainer.pl...
>
> regards,
> dan carpenter
>
>