From: "Mats Randgaard (matrandg)" <matrandg@cisco.com>
To: Mauro Carvalho Chehab <mchehab@osg.samsung.com>,
Linux Media Mailing List <linux-media@vger.kernel.org>
Cc: Mauro Carvalho Chehab <mchehab@infradead.org>
Subject: Re: [PATCH 1/4] tc358743: don't use variable length array for I2C writes
Date: Wed, 12 Aug 2015 14:24:27 +0200 [thread overview]
Message-ID: <55CB3AFB.50606@cisco.com> (raw)
In-Reply-To: <9d8c095a232ee176d14947bbe1330e1e3fbbde4c.1439306295.git.mchehab@osg.samsung.com>
On 08/11/2015 05:18 PM, Mauro Carvalho Chehab wrote:
> drivers/media/i2c/tc358743.c:148:19: warning: Variable length array is used.
>
> As the maximum size is 1026, we can't use dynamic var, as it
> would otherwise spend 1056 bytes of the stack at i2c_wr() function.
>
> So, allocate a buffer with the allowed maximum size together with
> the state var.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
>
> diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c
> index 2e926317d7e9..fe42c9a1cb78 100644
> --- a/drivers/media/i2c/tc358743.c
> +++ b/drivers/media/i2c/tc358743.c
> @@ -59,6 +59,9 @@ MODULE_LICENSE("GPL");
> #define EDID_NUM_BLOCKS_MAX 8
> #define EDID_BLOCK_SIZE 128
>
> +/* Max transfer size done by I2C transfer functions */
> +#define MAX_XFER_SIZE (EDID_NUM_BLOCKS_MAX * EDID_BLOCK_SIZE + 2)
> +
> static const struct v4l2_dv_timings_cap tc358743_timings_cap = {
> .type = V4L2_DV_BT_656_1120,
> /* keep this initialization for compatibility with GCC < 4.4.6 */
> @@ -94,6 +97,9 @@ struct tc358743_state {
> /* edid */
> u8 edid_blocks_written;
>
> + /* used by i2c_wr() */
> + u8 wr_data[MAX_XFER_SIZE];
> +
> struct v4l2_dv_timings timings;
> u32 mbus_fmt_code;
>
> @@ -143,9 +149,13 @@ static void i2c_wr(struct v4l2_subdev *sd, u16 reg, u8 *values, u32 n)
> {
> struct tc358743_state *state = to_state(sd);
> struct i2c_client *client = state->i2c_client;
> + u8 *data = state->wr_data;
> int err, i;
> struct i2c_msg msg;
> - u8 data[2 + n];
> +
> + if ((2 + n) > sizeof(state->wr_data))
> + v4l2_warn(sd, "i2c wr reg=%04x: len=%d is too big!\n",
> + reg, 2 + n);
>
> msg.addr = client->addr;
> msg.buf = data;
Acked-by: Mats Randgaard <matrandg@cisco.com>
next prev parent reply other threads:[~2015-08-12 12:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-11 15:18 [PATCH 1/4] tc358743: don't use variable length array for I2C writes Mauro Carvalho Chehab
2015-08-11 15:18 ` [PATCH 2/4] ov9650: remove an extra space Mauro Carvalho Chehab
2015-08-11 15:18 ` [PATCH 3/4] ov2659: get rid of unused values Mauro Carvalho Chehab
2015-08-11 15:18 ` [PATCH 4/4] sr030pc30: don't read a new pointer Mauro Carvalho Chehab
2015-08-12 12:24 ` Mats Randgaard (matrandg) [this message]
-- strict thread matches above, loose matches on Subject: below --
2015-08-11 15:13 [PATCH 1/4] tc358743: don't use variable length array for I2C writes Mauro Carvalho Chehab
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=55CB3AFB.50606@cisco.com \
--to=matrandg@cisco.com \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@infradead.org \
--cc=mchehab@osg.samsung.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.