From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Fleming Subject: Re: [PATCH 1/3] efi/efi_test: use memdup_user() as a cleanup Date: Mon, 3 Oct 2016 21:17:18 +0100 Message-ID: <20161003201718.GL16071@codeblueprint.co.uk> References: <1474859691-8574-1-git-send-email-ivan.hu@canonical.com> <1474859691-8574-2-git-send-email-ivan.hu@canonical.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <1474859691-8574-2-git-send-email-ivan.hu-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org> Sender: linux-efi-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Ivan Hu Cc: linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Ard Biesheuvel List-Id: linux-efi@vger.kernel.org On Mon, 26 Sep, at 11:14:49AM, Ivan Hu wrote: > Cleanup the warning, > drivers/firmware/efi/test/efi_test.c:269:8-15: WARNING opportunity for > memdup_user > > Use memdup_user rather than duplicating its implementation > This is a little bit restricted to reduce false positives I don't understand this sentence. What restriction are you talking about? > Generated by: coccinelle/api/memdup_user.coc > > Signed-off-by: Ivan Hu > --- > drivers/firmware/efi/test/efi_test.c | 10 +++------- > 1 file changed, 3 insertions(+), 7 deletions(-) > > diff --git a/drivers/firmware/efi/test/efi_test.c b/drivers/firmware/efi/test/efi_test.c > index f61bb52..5602c46 100644 > --- a/drivers/firmware/efi/test/efi_test.c > +++ b/drivers/firmware/efi/test/efi_test.c > @@ -266,14 +266,10 @@ static long efi_runtime_set_variable(unsigned long arg) > return rv; > } > > - data = kmalloc(setvariable.data_size, GFP_KERNEL); > - if (!data) { > + data = memdup_user(setvariable.data, setvariable.data_size); > + if (IS_ERR(data)) { > kfree(name); > - return -ENOMEM; > - } > - if (copy_from_user(data, setvariable.data, setvariable.data_size)) { > - rv = -EFAULT; > - goto out; > + return PTR_ERR(data); > } > > status = efi.set_variable(name, &vendor_guid, > -- > 1.9.1 >