Re: [PATCH] gpib: lpvo_usb: rewrite DLE/STX sequence validation using !(A && B) for clarity

From: Johan Hovold

Date: Mon May 18 2026 - 07:12:06 EST


On Sat, May 16, 2026 at 11:12:27AM +0800, sunliming@xxxxxxxxxxxxxxxxxx wrote:
> From: sunliming <sunliming@xxxxxxxxxx>
>
> Fix below smatch warnings:
> drivers/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c:808 usb_gpib_read() warn: was
> && intended here instead of ||?

This warning doesn't apply here where the two calls to one_char() return
different values.

It's meant to catch cases where the wrong operator is used so that a
condition is always true:

(x != a || x != b) <=> !(x == a && x == b) <=> true (a != b)

> Signed-off-by: sunliming <sunliming@xxxxxxxxxx>
> ---
> drivers/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c b/drivers/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c
> index e6ea9422d6f2..3e09f8226a56 100644
> --- a/drivers/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c
> +++ b/drivers/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c
> @@ -802,7 +802,7 @@ static int usb_gpib_read(struct gpib_board *board,
> if (retval < 0)
> goto read_return;
>
> - if (one_char(board, &b) != DLE || one_char(board, &b) != STX) {
> + if (!(one_char(board, &b) == DLE && one_char(board, &b) == STX)) {

Whether one prefer one over the other here is just a matter of taste.

> dev_err(board->gpib_dev, "wrong <DLE><STX> sequence\n");
> retval = -EIO;
> goto read_return;

Johan