Re: [PATCH] scsi: use set_host_byte instead of open-coding it

From: Steffen Maier
Date: Wed Oct 11 2017 - 09:05:51 EST



On 10/10/2017 05:29 PM, Johannes Thumshirn wrote:
Call set_host_byte() instead of open-coding it.

Converted using this simple Coccinelle spatch

<SmPL>
@@
local idexpression struct scsi_cmnd *c;
expression E1;
@@

- c->result = E1 << 16;
+ set_host_byte(c, E1);

Maybe I misunderstand, but doesn't set_host_byte only set the host byte but leave the other 3 parts untouched in c->result?

static inline void set_host_byte(struct scsi_cmnd *cmd, char status)
{
cmd->result = (cmd->result & 0xff00ffff) | (status << 16);
}

In contrast, assigning something to c->result resets all parts.
If so, the semantic patch would introduce a subtle semantic change.
Unless it's guaranteed that in all the touched cases, c->result always has 0 for status, message, and driver byte before calling set_host_byte().

Bart's suggestion also sounds nice.

FYI: Originally, I only thought about using set_host_byte in that one place fix of yours; I did not expect a full framework rework.

--
Mit freundlichen GrÃÃen / Kind regards
Steffen Maier

Linux on z Systems Development

IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294