答复: [PATCH net-next] net: ipv4: use BUG_ON instead of if condition followed by BUG

From: zhengyongjun
Date: Mon Jun 07 2021 - 10:25:08 EST


Thanks for your advice, I will do as your advice and send patch ' 0001-net-ipv4-Remove-unneed-BUG-function.patch ' :)

-----邮件原件-----
发件人: David Ahern [mailto:dsahern@xxxxxxxxx]
发送时间: 2021年6月7日 21:00
收件人: zhengyongjun <zhengyongjun3@xxxxxxxxxx>; davem@xxxxxxxxxxxxx; yoshfuji@xxxxxxxxxxxxxx; dsahern@xxxxxxxxxx; kuba@xxxxxxxxxx; netdev@xxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx
主题: Re: [PATCH net-next] net: ipv4: use BUG_ON instead of if condition followed by BUG

On 6/7/21 3:11 AM, Zheng Yongjun wrote:
> Use BUG_ON instead of if condition followed by BUG in inet_set_link_af.
>
> This issue was detected with the help of Coccinelle.
>
> Signed-off-by: Zheng Yongjun <zhengyongjun3@xxxxxxxxxx>
> ---
> net/ipv4/devinet.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index
> 2e35f68da40a..e3e1e8a600ef 100644
> --- a/net/ipv4/devinet.c
> +++ b/net/ipv4/devinet.c
> @@ -1988,8 +1988,7 @@ static int inet_set_link_af(struct net_device *dev, const struct nlattr *nla,
> if (!in_dev)
> return -EAFNOSUPPORT;
>
> - if (nla_parse_nested_deprecated(tb, IFLA_INET_MAX, nla, NULL, NULL) < 0)
> - BUG();
> + BUG_ON(nla_parse_nested_deprecated(tb, IFLA_INET_MAX, nla, NULL,
> +NULL) < 0);
>
> if (tb[IFLA_INET_CONF]) {
> nla_for_each_nested(a, tb[IFLA_INET_CONF], rem)
>

no reason to have a BUG here at all. Catch the error and return.