Skip to content

bq27441: Fix checksum overflow in compute_block_checksum(). #162

@nedseb

Description

@nedseb

Problem

compute_block_checksum() sums 32 bytes from the block data registers. When the sum exceeds 255, 255 - csum produces a negative value, which causes ValueError: bytes value out of range when passed to bytes() in _write_reg().

This breaks __init__()power_on()set_capacity()write_extended_data() on real hardware. The bug has existed since the initial driver commit but was never caught by mock tests (which return zeroed data).

Fix

# Before
csum = 255 - csum

# After
csum = (255 - (csum & 0xFF)) & 0xFF

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdriverConcerne un driver spécifiquereleased

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions