diff mbox

[v2,04/10] mfd: cros_ec: Use a zero-length array for command data

Message ID 55512034.3000206@collabora.co.uk (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Javier Martinez Canillas May 11, 2015, 9:33 p.m. UTC
Hello,

Thanks all for testing and sorry for this issue.

On 05/11/2015 10:19 PM, Gwendal Grignou wrote:
> On Sat, May 9, 2015 at 3:10 AM, Javier Martinez Canillas
> <javier.martinez@collabora.co.uk> wrote:

[snip]

>>
>>  static u32 ec_i2c_functionality(struct i2c_adapter *adap)
>> diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c
>> index b50c5b8b8a4d..090f8a75412a 100644
>> --- a/drivers/input/keyboard/cros_ec_keyb.c
>> +++ b/drivers/input/keyboard/cros_ec_keyb.c
>> @@ -149,16 +149,19 @@ static void cros_ec_keyb_process(struct cros_ec_keyb *ckdev,
>>  static int cros_ec_keyb_get_state(struct cros_ec_keyb *ckdev, uint8_t *kb_state)
>>  {
>>         int ret;
>> -       struct cros_ec_command msg = {
>> -               .command = EC_CMD_MKBP_STATE,
>> -               .insize = ckdev->cols,
>> -       };
>> +       struct cros_ec_command *msg = (struct cros_ec_command *)kb_state;
> Following amstan@ comments in 00/10 patch,
> I think there is something wrong here:
> kb_state should already have a cros_ec_command header, so that the
> lower layer can
> copy into the 'old' kb_state array directly.
> There will be no need for the memcpy later.
> 

True, the memcpy should not be needed but I copied at the beginning of kb_state
to avoid having to compute the kb_state + sizeof(struct cros_ec_command) offset
in cros_ec_keyb_process().

> Gwendal.
>>
>> -       ret = cros_ec_cmd_xfer(ckdev->ec, &msg);
>> -       if (ret < 0)
>> +       msg->command = EC_CMD_MKBP_STATE;
>> +       msg->insize = ckdev->cols;
>> +       msg->outsize = 0;
>> +

As Alexandru said, the EC is returning EC_RES_INVALID_VERSION and looking at
this code I see that there is a difference since v1 was using designated
initializers when declaring the struct cros_ec_command as a local variable in
the stack.

But in v2 the struct members are explicitly initialized since kb_state is not
initialized and I missed the version field so now it has an undefined value.

Heiko, Alexandru,

I don't have access to my Chromebooks right now but could you please test the
following patch [0] to see if that is the problem?

It seems I got it working on my test just out of luck since it happened that
version was initialized to 0 due the data it was on the stack.

Tomorrow when I've access to the Chromebooks I'll do more extensive testing
and see if I can reproduce the issue and if my assumption is correct.

Best regards,
Javier

[0]
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Heiko Stübner May 11, 2015, 9:47 p.m. UTC | #1
> Heiko, Alexandru,
> 
> I don't have access to my Chromebooks right now but could you please test
> the following patch [0] to see if that is the problem?
> 
> It seems I got it working on my test just out of luck since it happened that
> version was initialized to 0 due the data it was on the stack.
> 
> Tomorrow when I've access to the Chromebooks I'll do more extensive testing
> and see if I can reproduce the issue and if my assumption is correct.
> 
> Best regards,
> Javier
> 
> [0]
> diff --git a/drivers/input/keyboard/cros_ec_keyb.c
> b/drivers/input/keyboard/cros_ec_keyb.c index ef3ba20f4560..4f233e248a4d
> 100644
> --- a/drivers/input/keyboard/cros_ec_keyb.c
> +++ b/drivers/input/keyboard/cros_ec_keyb.c
> @@ -151,6 +151,7 @@ static int cros_ec_keyb_get_state(struct cros_ec_keyb
> *ckdev, uint8_t *kb_state) int ret;
>  	struct cros_ec_command *msg = (struct cros_ec_command *)kb_state;
> 
> +	msg->version = 0;
>  	msg->command = EC_CMD_MKBP_STATE;
>  	msg->insize = ckdev->cols;
>  	msg->outsize = 0;

on my rk3288-pinky this seems to fix the issue ... keyboard works out of the 
box again.


Heiko
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Javier Martinez Canillas May 11, 2015, 9:53 p.m. UTC | #2
Hello Heiko and Alexandru,

On 05/11/2015 11:47 PM, Heiko Stuebner wrote:
>> Heiko, Alexandru,
>> 
>> I don't have access to my Chromebooks right now but could you please test
>> the following patch [0] to see if that is the problem?
>> 
>> It seems I got it working on my test just out of luck since it happened that
>> version was initialized to 0 due the data it was on the stack.
>> 
>> Tomorrow when I've access to the Chromebooks I'll do more extensive testing
>> and see if I can reproduce the issue and if my assumption is correct.
>> 
>> Best regards,
>> Javier
>> 
>> [0]
>> diff --git a/drivers/input/keyboard/cros_ec_keyb.c
>> b/drivers/input/keyboard/cros_ec_keyb.c index ef3ba20f4560..4f233e248a4d
>> 100644
>> --- a/drivers/input/keyboard/cros_ec_keyb.c
>> +++ b/drivers/input/keyboard/cros_ec_keyb.c
>> @@ -151,6 +151,7 @@ static int cros_ec_keyb_get_state(struct cros_ec_keyb
>> *ckdev, uint8_t *kb_state) int ret;
>>  	struct cros_ec_command *msg = (struct cros_ec_command *)kb_state;
>> 
>> +	msg->version = 0;
>>  	msg->command = EC_CMD_MKBP_STATE;
>>  	msg->insize = ckdev->cols;
>>  	msg->outsize = 0;
> 
> on my rk3288-pinky this seems to fix the issue ... keyboard works out of the 
> box again.
>

Thank you both for testing the fix and again sorry for the silly mistake...

I'll wait a couple of days to see if I get more feedback and re-spin a v3
of the series with this fix patch squashed.
 
> 
> Heiko
>

Best regards,
Javier
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c
index ef3ba20f4560..4f233e248a4d 100644
--- a/drivers/input/keyboard/cros_ec_keyb.c
+++ b/drivers/input/keyboard/cros_ec_keyb.c
@@ -151,6 +151,7 @@  static int cros_ec_keyb_get_state(struct cros_ec_keyb *ckdev, uint8_t *kb_state)
 	int ret;
 	struct cros_ec_command *msg = (struct cros_ec_command *)kb_state;
 
+	msg->version = 0;
 	msg->command = EC_CMD_MKBP_STATE;
 	msg->insize = ckdev->cols;
 	msg->outsize = 0;