[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1520635631.2907.16.camel@wdc.com>
Date: Fri, 9 Mar 2018 22:47:12 +0000
From: Bart Van Assche <Bart.VanAssche@....com>
To: "jejb@...ux.vnet.ibm.com" <jejb@...ux.vnet.ibm.com>,
"steve@....org" <steve@....org>, "hare@...e.com" <hare@...e.com>,
"martin.petersen@...cle.com" <martin.petersen@...cle.com>,
"axboe@...nel.dk" <axboe@...nel.dk>
CC: "linux-scsi@...r.kernel.org" <linux-scsi@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-block@...r.kernel.org" <linux-block@...r.kernel.org>,
"kernel-hardening@...ts.openwall.com"
<kernel-hardening@...ts.openwall.com>
Subject: Re: [PATCH] scsi: resolve COMMAND_SIZE at compile time
On Fri, 2018-03-09 at 23:33 +0100, Stephen Kitt wrote:
> +/*
> + * SCSI command sizes are as follows, in bytes, for fixed size commands, per
> + * group: 6, 10, 10, 12, 16, 12, 10, 10. The top three bits of an opcode
> + * determine its group.
> + * The size table is encoded into a 32-bit value by subtracting each value
> + * from 16, resulting in a value of 1715488362
> + * (6 << 28 + 6 << 24 + 4 << 20 + 0 << 16 + 4 << 12 + 6 << 8 + 6 << 4 + 10).
> + * Command group 3 is reserved and should never be used.
> + */
> +#define COMMAND_SIZE(opcode) \
> + (16 - (15 & (1715488362 >> (4 * (((opcode) >> 5) & 7)))))
To me this seems hard to read and hard to verify. Could this have been written
as a combination of ternary expressions, e.g. using a gcc statement expression
to ensure that opcode is evaluated once?
Thanks,
Bart.
Powered by blists - more mailing lists