Re: [PATCH v1] media: si2168: Refactor command setup code

Marc Gonzalez
2019-07-03T14:15:42Z

On 03/07/2019 14:47, Marc Gonzalez wrote:

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

My idea is to use a trivial helper function to assign the 3 struct fields,
and then a trivial macro to invoke the helper:

static void cmd_setup(struct si2168_cmd *cmd, char *args, int wlen, int rlen)
{
memcpy(cmd->args, args, wlen);
cmd->wlen = wlen;
cmd->rlen = rlen;
}

#define CMD_SETUP(cmd, args, rlen) \
cmd_setup(cmd, args, sizeof(args) - 1, rlen)

I think this way addresses all of your comments:

- since we're using a real function, the compiler can perform type-checking,
and the function's prototype is self-documenting.
- no more funky __args and __rlen arguments
- no local variables

Note however, that drivers/media/tuners/si2157.c uses a different struct
(struct si2157_cmd). Therefore, if we wanted to apply the same changes
to si2157.c, we would have to define a common struct, and replace all
the uses of struct si2157_cmd and struct si2168_cmd. That seemed too
invasive to do without the maintainer's approval and guidance.

Antti, do you Ack this new approach?

It's not clear what HW is supported by drivers/media/dvb-frontends/si21xx.c
(that's a very generic name).

Regards.