Re: [PATCH v5 3/6] lib/base64: rework encode/decode for speed and stricter validation

Andrew Morton
2025-11-17T17:46:55Z

On Sun, 16 Nov 2025 18:28:49 +0800 Guan-Chun Wu <409411716@gms.tku.edu.tw> wrote:

> > Reviewed-by: David Laight <david.laight.linux@gmail.com>
> >
> > But see minor nit below.
>
> Hi David,
>
> Thanks for the review and for pointing this out.
>
> Andrew, would it be possible for you to fold this small change
> (removing the redundant casts) directly when updating the patch?
> If that’s not convenient, I can resend an updated version of the
> series instead.

Sure, I added this:

--- a/lib/base64.c~lib-base64-rework-encode-decode-for-speed-and-stricter-validation-fix
+++ a/lib/base64.c
@@ -83,7 +83,7 @@ int base64_encode(const u8 *src, int src
const char *base64_table = base64_tables[variant];

while (srclen >= 3) {
- ac = (u32)src[0] << 16 | (u32)src[1] << 8 | (u32)src[2];
+ ac = src[0] << 16 | src[1] << 8 | src[2];
*cp++ = base64_table[ac >> 18];
*cp++ = base64_table[(ac >> 12) & 0x3f];
*cp++ = base64_table[(ac >> 6) & 0x3f];
@@ -95,7 +95,7 @@ int base64_encode(const u8 *src, int src

switch (srclen) {
case 2:
- ac = (u32)src[0] << 16 | (u32)src[1] << 8;
+ ac = src[0] << 16 | src[1] << 8;
*cp++ = base64_table[ac >> 18];
*cp++ = base64_table[(ac >> 12) & 0x3f];
*cp++ = base64_table[(ac >> 6) & 0x3f];
@@ -103,7 +103,7 @@ int base64_encode(const u8 *src, int src
*cp++ = '=';
break;
case 1:
- ac = (u32)src[0] << 16;
+ ac = src[0] << 16;
*cp++ = base64_table[ac >> 18];
*cp++ = base64_table[(ac >> 12) & 0x3f];
if (padding) {
_