Yes, you are right with the return code of the getsockopt() function. Your changes fix the error case handling.
> -----Original Message----- > From: Changwoo Kang <[email protected]> > Sent: Tuesday, November 24, 2026 4:24 PM > To: [email protected] > Cc: Thomas Monjalon <[email protected]>; Stephen Hemminger > <[email protected]>; Changwoo Kang > <[email protected]>; [email protected]; Stefan Lässer > <[email protected]> > Subject: [PATCH] net/af_packet: fix drop count error check > > [You don't often get email from [email protected]. Learn why > this is important at https://aka.ms/LearnAboutSenderIdentification ] > > getsockopt() returns 0 on success and -1 on error, so the check "< -1" is > never > true. On failure the function returned an uninitialized value. Check for "< 0" > instead. > > Fixes: 6b3246245507 ("net/af_packet: provide packet drop stats") > Cc: [email protected] > Cc: Stefan Laesser <[email protected]> > > Signed-off-by: Changwoo Kang <[email protected]> > --- > .mailmap | 1 + > drivers/net/af_packet/rte_eth_af_packet.c | 2 +- > 2 files changed, 2 insertions(+), 1 deletion(-) > > diff --git a/.mailmap b/.mailmap > index a0096fb97a..ed6e68cc1b 100644 > --- a/.mailmap > +++ b/.mailmap > @@ -264,6 +264,7 @@ Changchun Ouyang <[email protected]> > Changpeng Liu <[email protected]> Changqi Dingluo > <[email protected]> Changqing Wu > <[email protected]> > +Changwoo Kang <[email protected]> > Chao Zhu <[email protected]> <[email protected]> Chaoyong > He <[email protected]> Charles Brett <[email protected]> diff --git > a/drivers/net/af_packet/rte_eth_af_packet.c > b/drivers/net/af_packet/rte_eth_af_packet.c > index fbaea57615..ad71582aea 100644 > --- a/drivers/net/af_packet/rte_eth_af_packet.c > +++ b/drivers/net/af_packet/rte_eth_af_packet.c > @@ -518,7 +518,7 @@ packet_drop_count(int sockfd) > return 0; > > if (getsockopt(sockfd, SOL_PACKET, PACKET_STATISTICS, &pkt_stats, > - &pkt_stats_len) < -1) > + &pkt_stats_len) < 0) > return 0; > > return pkt_stats.tp_drops; > -- > 2.36.0

