lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6a644c94-f979-b656-472b-c7fe9303e08c@free.fr>
Date:   Wed, 3 Jul 2019 14:47:59 +0200
From:   Marc Gonzalez <marc.w.gonzalez@...e.fr>
To:     Jonathan Neuschäfer <j.neuschaefer@....net>
Cc:     Antti Palosaari <crope@....fi>,
        Mauro Carvalho Chehab <mchehab@...nel.org>,
        linux-media <linux-media@...r.kernel.org>,
        LKML <linux-kernel@...r.kernel.org>,
        Bjorn Andersson <bjorn.andersson@...aro.org>,
        Brad Love <brad@...tdimension.cc>
Subject: Re: [PATCH v1] media: si2168: Refactor command setup code

On 02/07/2019 11:51, Jonathan Neuschäfer wrote:

> On Mon, Jul 01, 2019 at 01:44:09PM +0200, Marc Gonzalez wrote:
>
>> By refactoring the command setup code, we can let the compiler
>> determine the size of each command.
> 
> I like the idea, it definitely saves some code.
> 
> The conversion also looks correct.
> 
>> Signed-off-by: Marc Gonzalez <marc.w.gonzalez@...e.fr>
>> ---
>>  drivers/media/dvb-frontends/si2168.c | 142 ++++++++-------------------
>>  1 file changed, 41 insertions(+), 101 deletions(-)
>>
>> diff --git a/drivers/media/dvb-frontends/si2168.c b/drivers/media/dvb-frontends/si2168.c
>> index 168c503e9154..19398f041c79 100644
>> --- a/drivers/media/dvb-frontends/si2168.c
>> +++ b/drivers/media/dvb-frontends/si2168.c
>> @@ -11,6 +11,12 @@
>>  
>>  static const struct dvb_frontend_ops si2168_ops;
>>  
>> +#define CMD_SETUP(cmd, __args, __rlen) do {	\
>> +	int wlen = sizeof(__args) - 1;		\
>> +	memcpy(cmd.args, __args, wlen);		\
>> +	cmd.wlen = wlen; cmd.rlen = __rlen;	\
>> +} while (0)
> 
> It would be nice for casual readers to have a little comment here, that
> explains (briefly) what this macro does, and what the arguments mean,
> and their types.

Just a bit of background.

A macro is required /at some point/ because arrays "decay" into pointers
when used as function arguments.

Come to think of it, I'm really not a fan of "large" macro functions.
I'll outline a different option in v2.


> Why cmd rather than __cmd? This seems inconsistent.

Note: I hate using underscores in macro argument names, but they clashed
with the struct field names. There was no such clash for 'cmd'.


> The wlen local variable can be avoided by a bit of suffling:
> 
> 	#define CMD_SETUP(cmd, __args, __rlen) do {	\
> 		cmd.rlen = __rlen;			\
> 		cmd.wlen = sizeof(__args) - 1;		\
> 		memcpy(cmd.args, __args, cmd.wlen);	\
> 	} while (0)

Do you think it is important to avoid a local variable?


>> Not sure where to store the macro. Maybe include/media/dvb_frontend.h?
> 
> Then include/media/dvb_frontend.h would contain information about the
> private structs of a few (two) drivers. This doesn't seem like a good
> idea to me.

You're right. I found a better place.

Regards.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ