提交 f7929436 编写于 作者: G Geliang Tang 提交者: Mark Brown

spi: spidev: use memdup_user

Use memdup_user() helper instead of open-coding to simplify the code.
Signed-off-by: NGeliang Tang <geliangtang@gmail.com>
Reviewed-by: NGeert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: NMark Brown <broonie@kernel.org>
上级 76bf5694
...@@ -324,7 +324,6 @@ static struct spi_ioc_transfer * ...@@ -324,7 +324,6 @@ static struct spi_ioc_transfer *
spidev_get_ioc_message(unsigned int cmd, struct spi_ioc_transfer __user *u_ioc, spidev_get_ioc_message(unsigned int cmd, struct spi_ioc_transfer __user *u_ioc,
unsigned *n_ioc) unsigned *n_ioc)
{ {
struct spi_ioc_transfer *ioc;
u32 tmp; u32 tmp;
/* Check type, command number and direction */ /* Check type, command number and direction */
...@@ -341,14 +340,7 @@ spidev_get_ioc_message(unsigned int cmd, struct spi_ioc_transfer __user *u_ioc, ...@@ -341,14 +340,7 @@ spidev_get_ioc_message(unsigned int cmd, struct spi_ioc_transfer __user *u_ioc,
return NULL; return NULL;
/* copy into scratch area */ /* copy into scratch area */
ioc = kmalloc(tmp, GFP_KERNEL); return memdup_user(u_ioc, tmp);
if (!ioc)
return ERR_PTR(-ENOMEM);
if (__copy_from_user(ioc, u_ioc, tmp)) {
kfree(ioc);
return ERR_PTR(-EFAULT);
}
return ioc;
} }
static long static long
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册