linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin Fuzzey <martin.fuzzey@flowbird.group>
To: Sebastian Reichel <sebastian.reichel@collabora.com>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Ahmet Inan <inan@distec.de>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel@collabora.com
Subject: Re: [PATCHv1 2/2] Input: EXC3000: Add support to query model and fw_version
Date: Fri, 22 Nov 2019 18:43:48 +0100	[thread overview]
Message-ID: <4ee3ce4f-f544-700c-bc8d-817cea35137a@flowbird.group> (raw)
In-Reply-To: <20191107181010.17211-2-sebastian.reichel@collabora.com>

Hi Sebastian,

On 07/11/2019 19:10, Sebastian Reichel wrote:
> Expose model and fw_version via sysfs. Also query the model
> in probe to make sure, that the I2C communication with the
> device works before successfully probing the driver.
>
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
> ---
>   drivers/input/touchscreen/exc3000.c | 136 ++++++++++++++++++++++++++++
>   1 file changed, 136 insertions(+)
>
> diff --git a/drivers/input/touchscreen/exc3000.c b/drivers/input/touchscreen/exc3000.c
> index 7d695022082c..4c9f132629b9 100644
> --- a/drivers/input/touchscreen/exc3000.c
> +++ b/drivers/input/touchscreen/exc3000.c
> @@ -41,6 +41,11 @@ struct exc3000_data {
>   	struct touchscreen_properties prop;
>   	struct timer_list timer;
>   	u8 buf[2 * EXC3000_LEN_FRAME];
> +	char model[11];
> +	char fw_version[6];

These buffers are too small.

I know those are the values shown in the EETI "I2C Programming Guide" 
but, on my exc80H32 I have 16 bytes for the model and 14 for the fw_version.

It may even be possible to have larger, depends on the firmware / config 
blob that has been loaded.

The guide seems to be mostly an example. As nothing else is sent in the 
reply message, worst case the full frame would be filled.


>   
> +static void exc3000_query_interrupt(struct exc3000_data *data)
> +{
> +	u8 *buf = data->buf;
> +	int err;
> +
> +	data->query_result = 0;
> +
> +	err = i2c_master_recv(data->client, buf, EXC3000_LEN_FRAME);
> +	if (err < 0) {
> +		data->query_result = err;
> +		goto out;
> +	}
> +
> +	if (buf[0] == 0x42 && buf[4] == 'E') {
> +		memcpy(data->model, buf+5, 10);
> +		data->model[10] = '\0';

Maybe use sizeof() to avoid the hard coded 10?

> +		goto out;
> +	} else if (buf[0] == 0x42 && buf[4] == 'D') {
> +		memcpy(data->fw_version, buf+5, 5);
> +		data->fw_version[5] = '\0';
> +		goto out;
> +	}
> +


Ok so at least there won't be a buffer overflow but it will truncate.


> +static DEVICE_ATTR(fw_version, S_IRUGO, exc3000_get_fw_version, NULL);
> +


Maybe use DEVICE_ATTR_RO  to reduce the amount of boilerplate?


> +	input->dev.groups = exc3000_attribute_groups;


Hum, this adds the attributes to the input device (in /sys/class/input) 
but these attributes are really for the whole I2C device.

Wouldn't it be better to use devm_device_add_group() to add them to the 
I2C device?


> +	for (retry = 0; retry < 3; ++retry) {
> +		error = exc3000_get_model(data);
> +		if (!error) {
> +			break;
> +		}
> +		dev_warn(&client->dev, "Retry %d get EETI EXC3000 model: %d\n", retry + 1, error);
> +	}
> +


Is there a particular reason why retries are needed?


Regards,


Martin


  parent reply	other threads:[~2019-11-22 17:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-07 18:10 [PATCHv1 1/2] Input: EXC3000: add EXC80Hxx support Sebastian Reichel
2019-11-07 18:10 ` [PATCHv1 2/2] Input: EXC3000: Add support to query model and fw_version Sebastian Reichel
2019-11-13  0:23   ` Dmitry Torokhov
2019-11-20 11:47     ` Martin Fuzzey
2019-11-22 17:43   ` Martin Fuzzey [this message]
2019-11-13  0:19 ` [PATCHv1 1/2] Input: EXC3000: add EXC80Hxx support Dmitry Torokhov
2019-11-20 11:32 ` Martin Fuzzey

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=4ee3ce4f-f544-700c-bc8d-817cea35137a@flowbird.group \
    --to=martin.fuzzey@flowbird.group \
    --cc=dmitry.torokhov@gmail.com \
    --cc=inan@distec.de \
    --cc=kernel@collabora.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sebastian.reichel@collabora.com \
    /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).