From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753925AbcHTJdB (ORCPT ); Sat, 20 Aug 2016 05:33:01 -0400 Received: from mx01-fr.bfs.de ([193.174.231.67]:14179 "EHLO mx01-fr.bfs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752449AbcHTJc7 (ORCPT ); Sat, 20 Aug 2016 05:32:59 -0400 Message-ID: <57B823C7.3040705@bfs.de> Date: Sat, 20 Aug 2016 11:32:55 +0200 From: walter harms Reply-To: wharms@bfs.de User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.1.16) Gecko/20101125 SUSE/3.0.11 Thunderbird/3.0.11 MIME-Version: 1.0 CC: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, Leon Romanovsky , Matan Barak , LKML , kernel-janitors@vger.kernel.org, Julia Lawall Subject: Re: [PATCH] mlx5/core: Use memdup_user() rather than duplicating its implementation References: <566ABCD9.1060404@users.sourceforge.net> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 20.08.2016 08:01, schrieb SF Markus Elfring: > From: Markus Elfring > Date: Sat, 20 Aug 2016 07:50:09 +0200 > > * Reuse existing functionality from memdup_user() instead of keeping > duplicate source code. > > This issue was detected by using the Coccinelle software. > > * Return directly if this copy operation failed. > > Signed-off-by: Markus Elfring > --- > drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 17 +++-------------- > 1 file changed, 3 insertions(+), 14 deletions(-) > > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c > index 6388bc0..bb89f04 100644 > --- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c > +++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c > @@ -1132,7 +1132,6 @@ static ssize_t data_write(struct file *filp, const char __user *buf, > struct mlx5_core_dev *dev = filp->private_data; > struct mlx5_cmd_debug *dbg = &dev->cmd.dbg; > void *ptr; > - int err; > > if (*pos != 0) > return -EINVAL; > @@ -1140,25 +1139,15 @@ static ssize_t data_write(struct file *filp, const char __user *buf, > kfree(dbg->in_msg); > dbg->in_msg = NULL; > dbg->inlen = 0; > - > - ptr = kzalloc(count, GFP_KERNEL); > - if (!ptr) > - return -ENOMEM; > - > - if (copy_from_user(ptr, buf, count)) { > - err = -EFAULT; > - goto out; > - } > + ptr = memdup_user(buf, count); > + if (IS_ERR(ptr)) > + return PTR_ERR(ptr); > dbg->in_msg = ptr; > dbg->inlen = count; > > *pos = count; > maybe i am missing something here but why do you need ptr ? The use of count looks even more confusing it is stored in dbg->inlen, *pos and is returned. is that realy needed ? re, wh > return count; > - > -out: > - kfree(ptr); > - return err; > } > > static ssize_t data_read(struct file *filp, char __user *buf, size_t count,