Re: [PATCH net-next] sock: Correct error checking condition for assign|release_proto_idx()
From: Zijun Hu
Date: Wed Apr 09 2025 - 20:51:08 EST
On 2025/4/9 02:21, Kuniyuki Iwashima wrote:
>> diff --git a/include/net/sock.h b/include/net/sock.h
>> index 8daf1b3b12c607d81920682139b53fee935c9bb5..9ece93a3dd044997276b0fa37dddc7b5bbdacc43 100644
>> --- a/include/net/sock.h
>> +++ b/include/net/sock.h
>> @@ -1421,7 +1421,10 @@ struct prot_inuse {
>> static inline void sock_prot_inuse_add(const struct net *net,
>> const struct proto *prot, int val)
>> {
>> - this_cpu_add(net->core.prot_inuse->val[prot->inuse_idx], val);
>> + unsigned int idx = prot->inuse_idx;
>> +
>> + if (likely(idx < PROTO_INUSE_NR))
>> + this_cpu_add(net->core.prot_inuse->val[idx], val);
> How does the else case happen ?
thank you for code review.
provided that @prot->inuse_idx will never be used if @prot fails to be
registered.
will remove this check in v2.