All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@kernel.org>
To: rkardell <rkardell@mida.se>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] media: dvb: qt1010, change i2c read buffer from stack, to kernel space
Date: Mon, 6 Dec 2021 16:01:53 +0100	[thread overview]
Message-ID: <20211206160153.120aefab@coco.lan> (raw)
In-Reply-To: <ccc99e48-de4f-045e-0fe4-61e3118e3f74@mida.se>

Hi,

This patch is broken on so many ways:

1. your e-mailer converted spaces and tabs into UTF spaces (0xa0);
2. it is not checking if allocation failed;
3. it doesn't fix the write function, which also uses stack;
4. you need your real name on your from and SoB.

Besides that, there's no issue on using the stack for I2C transfers.
The issue, is actually to use stack for USB transfers. 

So, the right fix should be, instead, at the bridge driver, and not
on tuner. It seems that Mega Sky 580 USB DVB is supportd by m920x driver.
Right?

If so, the enclosed patch should fix the issue.

Please test.

Regards,
Mauro

Em Thu, 7 Oct 2021 14:29:00 +0200
rkardell <rkardell@mida.se> escreveu:

> Solve problem with initialization of Mega Sky 580 USB DVB (and other 
> using mt352), error when reading i2c id.
> 
> 
> Signed-off-by: rkl099 <rkardell@mida.se>
> ---
>   drivers/media/tuners/qt1010.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/tuners/qt1010.c b/drivers/media/tuners/qt1010.c
> index 3853a3d43..1bc0756f7 100644
> --- a/drivers/media/tuners/qt1010.c
> +++ b/drivers/media/tuners/qt1010.c
> @@ -11,18 +11,22 @@
>   /* read single register */
>   static int qt1010_readreg(struct qt1010_priv *priv, u8 reg, u8 *val)
>   {
> +    u8 *b1=kmalloc(1,GFP_KERNEL);
>          struct i2c_msg msg[2] = {
>                  { .addr = priv->cfg->i2c_address,
>                    .flags = 0, .buf = &reg, .len = 1 },
>                  { .addr = priv->cfg->i2c_address,
> -                 .flags = I2C_M_RD, .buf = val, .len = 1 },
> +                 .flags = I2C_M_RD, .buf = b1, .len = 1 },
>          };
> 
>          if (i2c_transfer(priv->i2c, msg, 2) != 2) {
>                  dev_warn(&priv->i2c->dev, "%s: i2c rd failed reg=%02x\n",
>                                  KBUILD_MODNAME, reg);
> +           kfree(b1);
>                  return -EREMOTEIO;
>          }
> +       *val=b1[0];
> +       kfree(b1);
>          return 0;
>   }
> 

Thanks,
Mauro

[PATCH] media: m920x: don't use stack on USB reads

Using stack-allocated pointers for USB message data don't work.
This driver is almost OK with that, except for the I2C read
logic.

Fix it by using a temporary read buffer, just like on all other
calls to m920x_read().

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

diff --git a/drivers/media/usb/dvb-usb/m920x.c b/drivers/media/usb/dvb-usb/m920x.c
index 4bb5b82599a7..691e05833db1 100644
--- a/drivers/media/usb/dvb-usb/m920x.c
+++ b/drivers/media/usb/dvb-usb/m920x.c
@@ -274,6 +274,13 @@ static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int nu
 			/* Should check for ack here, if we knew how. */
 		}
 		if (msg[i].flags & I2C_M_RD) {
+			char *read = kmalloc(1, GFP_KERNEL);
+			if (!read) {
+				ret = -ENOMEM;
+				kfree(read);
+				goto unlock;
+			}
+
 			for (j = 0; j < msg[i].len; j++) {
 				/* Last byte of transaction?
 				 * Send STOP, otherwise send ACK. */
@@ -281,9 +288,12 @@ static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int nu
 
 				if ((ret = m920x_read(d->udev, M9206_I2C, 0x0,
 						      0x20 | stop,
-						      &msg[i].buf[j], 1)) != 0)
+						      read, 1)) != 0)
 					goto unlock;
+				msg[i].buf[j] = read[0];
 			}
+
+			kfree(read);
 		} else {
 			for (j = 0; j < msg[i].len; j++) {
 				/* Last byte of transaction? Then send STOP. */


      reply	other threads:[~2021-12-06 15:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-07 12:29 [PATCH] media: dvb: qt1010, change i2c read buffer from stack, to kernel space rkardell
2021-12-06 15:01 ` Mauro Carvalho Chehab [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=20211206160153.120aefab@coco.lan \
    --to=mchehab@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=rkardell@mida.se \
    /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.