Re: [PATCH 3/6] w1: Return actual bytes read from w1_read_block() and rw_read()

From: Krzysztof Kozlowski

Date: Wed Dec 02 2026 - 05:54:25 EST


On 02/12/2026 10:36, Lee Jones wrote:
> rw_read() discards the return value of w1_read_block() and always
> returns the requested count. When a bus master's read_block callback
> fails (for instance ds9490r_read_block() returning 0 on a USB error or
> allocation failure), buf is left untouched and rw_read() exposes up to
> PAGE_SIZE bytes of uninitialised kernel heap memory to userspace. In
> addition, w1_bus_master::read_block, w1_read_block(), and
> ds9490r_read_block() return u8, which truncates counts of 256 bytes or
> more (such as a PAGE_SIZE read).
>
> Widen the return type of read_block, w1_read_block(), and
> ds9490r_read_block() from u8 to int, return 0 in w1_read_block() when
> len is non-positive, and return the byte count from w1_read_block() in
> rw_read().
>
> Fixes: f522d2396138 ("[PATCH] w1: Added default generic read/write operations.")
> Closes: https://sashiko.dev/#/bug/linux-ea892b13-33ef-4375-ae35-db4cafb332c0
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
> ---

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@xxxxxxxxxxxxxxxx>

Best regards,
Krzysztof