Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1466529

Re: [PATCH] IB/qib: Use memdup_user() rather than duplicating its implementation

From Leon Romanovsky <leon@kernel.org>
Newsgroups linux.kernel
Subject Re: [PATCH] IB/qib: Use memdup_user() rather than duplicating its implementation
Date 2016-08-19 18:00 +0200
Message-ID <s7Uds-7rO-19@gated-at.bofh.it> (permalink)
References <s7M6e-2to-11@gated-at.bofh.it> <s7U3L-7oh-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Fri, Aug 19, 2016 at 03:27:20PM +0000, Marciniszyn, Mike wrote:
> > Subject: [PATCH] IB/qib: Use memdup_user() rather than duplicating its
> > diff --git a/drivers/infiniband/hw/qib/qib_fs.c
> 
> I would be even more aggressive at reducing lines of code.
> 
> For example do direct returns when ok to do:
>         if (pos != 0 || count != sizeof(struct qib_flash))
>                 return -EINVAL;
> 
>         tmp = memdup_user(buf, count);
>         if (IS_ERR(tmp))
>                 return PTR_ERR(tmp);
> 
> The bail_tmp: label is then not needed.

You still need to free tmp allocation if qib_eeprom_write failed and
this is your bail_tmp.

341         tmp = kmalloc(count, GFP_KERNEL);
342         if (!tmp) {
343                 ret = -ENOMEM;
344                 goto bail;
345         }
346
347         if (copy_from_user(tmp, buf, count)) {
348                 ret = -EFAULT;
349                 goto bail_tmp;
350         }
351
352         dd = private2dd(file);
353         if (qib_eeprom_write(dd, pos, tmp, count)) {
354                 ret = -ENXIO;
355                 qib_dev_err(dd, "failed to write to flash\n");
356                 goto bail_tmp;
357         }

> 
> Mike
> 

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] IB/qib: Use memdup_user() rather than duplicating its  implementation SF Markus Elfring <elfring@users.sourceforge.net> - 2016-08-19 09:10 +0200
  RE: [PATCH] IB/qib: Use memdup_user() rather than duplicating its  implementation "Marciniszyn, Mike" <mike.marciniszyn@intel.com> - 2016-08-19 17:40 +0200
    RE: [PATCH] IB/qib: Use memdup_user() rather than duplicating its  implementation "Marciniszyn, Mike" <mike.marciniszyn@intel.com> - 2016-08-19 17:50 +0200
      Re: [PATCH] IB/qib: Use memdup_user() rather than duplicating its  implementation Leon Romanovsky <leon@kernel.org> - 2016-08-19 17:50 +0200
    Re: [PATCH] IB/qib: Use memdup_user() rather than duplicating its  implementation Leon Romanovsky <leon@kernel.org> - 2016-08-19 18:00 +0200
    Re: [PATCH] IB/qib: Use memdup_user() rather than duplicating its  implementation Doug Ledford <dledford@redhat.com> - 2016-08-23 18:50 +0200
  Re: [PATCH] IB/qib: Use memdup_user() rather than duplicating its  implementation Leon Romanovsky <leon@kernel.org> - 2016-08-19 17:40 +0200

csiph-web