Re: [PATCH RESEND] staging: nvec: use strcmp() instead of strncmp() with magic length

Thierry Reding <[email protected]> Mon, 27 Jul 2026 17:58:20 +0200
Newsgroups org.kernel.vger.linux-tegra,dev.linux.lists.linux-staging
Message-ID <amd-EkmT_H1xlm7Q@orome>
On Thu, Jul 23, 2026 at 07:18:23PM +0300, Artem Lytkin wrote:
> Replace strncmp() with a hardcoded length of 30 with strcmp().
> The bat_type string is already null-terminated (set two lines above),
> so strncmp() with an arbitrary length is misleading and functionally
> equivalent to strcmp().
> 
> Signed-off-by: Artem Lytkin <[email protected]>
> ---
>  drivers/staging/nvec/nvec_power.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

I don't really see a point in this. strncmp() doesn't do any harm and it
isn't misleading either. It's just very explicit that it should never
check more than those 30 characters that can fit into the type string.

Technically res->length could be larger than 30, in which case the
memcpy() might copy more than those 30. Judging by the nvec core code we
never sanity check the length, so even that memcpy() could be entirely
wrong.

Either way, this change by itself doesn't look useful.

Thierry
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEEiOrDCAFJzPfAjcif3SOs138+s6EFAmpngBkACgkQ3SOs138+
s6H+Fw//Wmp1qIqT1zWam2BYIGXCmPAo4FTI6yde4DZ2lyxXncF94w1ijKRE4grD
ahPCG2WKTX1wbXyYfaXlpbJYrtDAEcio990FFfmbJHgAz+625Kj/XunCORuNY9zQ
jUlK53JdDlIGABEqZIpjxxclHwaGCu0fJeTZXKu3gt9lInyZKUChXqxpFTLTsB9A
lpF0kjj4ijneaMh3LSFZjmPrsmDdGTgogG4vgN4AkKiHuFdrojo9Vy6BjtCyzmJX
iYMgIxD3/1jcbryJ/TKNxwXoOXyW3ilNADy2hYmvkZeUxWOPBAtu35kLZSDKPyav
iooN167DZ91bsdKHyXbQdyL4acjX3f1JXZtDUurnRT1d4HwmTkdSuTjsrhrVUOdw
+UUq91jW7WBNDbbAsEsdn4zLlYzFsHRnKALv1qdlR/kRvBkLN35+bibEF+Ok8ni4
nFmMj94XomjvTCOiaJVojX1KOIOWTpKQQr5uKS9QU1Skrd7HInUchcjdwAaWEfu1
5RXhH6zPa+J8SEltRN6Kk7hdQWKKQ7nCMe0//agRBzGNa3gbgJ44wR29FcDX0EHq
wcUjgZ8/YTG/I5AIoptWfv+zlluHDjqU/qnhmEu00MbD0exo8ERLrUMW2Kvhq/NF
sPVvpVakkpnEP+MELHO+aeqvb0y6OPP/y7CnbcBr19jXTrRJ/5k=
=Mkpx
-----END PGP SIGNATURE-----