linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jonathan Neuschäfer" <j.neuschaefer@gmx.net>
To: Marc Gonzalez <marc.w.gonzalez@free.fr>
Cc: "Jonathan Neuschäfer" <j.neuschaefer@gmx.net>,
	"Antti Palosaari" <crope@iki.fi>,
	"Mauro Carvalho Chehab" <mchehab@kernel.org>,
	linux-media <linux-media@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	"Bjorn Andersson" <bjorn.andersson@linaro.org>,
	"Brad Love" <brad@nextdimension.cc>
Subject: Re: [PATCH v1] media: si2168: Refactor command setup code
Date: Wed, 3 Jul 2019 18:35:00 +0200	[thread overview]
Message-ID: <20190703163500.GF22408@latitude> (raw)
In-Reply-To: <6a644c94-f979-b656-472b-c7fe9303e08c@free.fr>

[-- Attachment #1: Type: text/plain, Size: 1884 bytes --]

Hi again,

On Wed, Jul 03, 2019 at 02:47:59PM +0200, Marc Gonzalez wrote:
> On 02/07/2019 11:51, Jonathan Neuschäfer wrote:
> > On Mon, Jul 01, 2019 at 01:44:09PM +0200, Marc Gonzalez wrote:
[...]
> >>  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.

*nod*

[ I should have been more specific: By "here" I meant at that spot in
  the code, and by casual readers I mostly meant casual readers of the
  code once it's merged. ]

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

The v2 approach looks nicer to me, thanks.

> > 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'.

Hmm, ok.

> > 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 exactly important, but wlen would be another name that can collide
with the name spaces of the functions where the macro is used and
trigger -Wshadow.


Greetings,
Jonathan Neuschäfer

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      parent reply	other threads:[~2019-07-03 16:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-01 11:44 [PATCH v1] media: si2168: Refactor command setup code Marc Gonzalez
2019-07-02  8:37 ` Marc Gonzalez
2019-07-02  9:51 ` Jonathan Neuschäfer
2019-07-03 12:47   ` Marc Gonzalez
2019-07-03 14:15     ` Marc Gonzalez
2019-07-03 16:35     ` Jonathan Neuschäfer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190703163500.GF22408@latitude \
    --to=j.neuschaefer@gmx.net \
    --cc=bjorn.andersson@linaro.org \
    --cc=brad@nextdimension.cc \
    --cc=crope@iki.fi \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=marc.w.gonzalez@free.fr \
    --cc=mchehab@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).