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
Problem
compute_block_checksum()sums 32 bytes from the block data registers. When the sum exceeds 255,255 - csumproduces a negative value, which causesValueError: bytes value out of rangewhen passed tobytes()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
Related