Re: [PATCH v5 1/2] iio: magnetometer: bmc150_magn: use automated cleanup for mutex

From: Ethan Tidmore

Date: Sun Feb 08 2026 - 00:15:01 EST


On Sat Feb 7, 2026 at 7:16 PM CST, Neel Bullywon wrote:
> Use guard() and scoped_guard() to replace manual mutex lock/unlock
> calls. This simplifies error handling and ensures RAII-style cleanup.
>
> Additionally, replace msleep(5) with fsleep(5000) to allow the kernel
> to select the most appropriate delay mechanism based on duration.

This should be its own patch. Please keep one logical change per patch.

>
> guard() is used in read_raw, write_raw, trig_reen, trigger_set_state,
> and resume. Case blocks in read_raw and write_raw are wrapped in braces
> to ensure clear scope for the cleanup guards.
>
> scoped_guard() is used in remove, runtime_suspend, and suspend where a
> short mutex-protected scope is needed for a single function call.
>
> The trigger_handler function is left unchanged as mixing guard() with
> goto error paths can be fragile.
>
> Signed-off-by: Neel Bullywon <neelb2403@xxxxxxxxx>

Thanks,

ET