Message ID | 1523887514-17444-1-git-send-email-festevam@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Herbert Xu |
Headers | show |
On Mon, Apr 16, 2018 at 11:05:14AM -0300, Fabio Estevam wrote: > From: Fabio Estevam <fabio.estevam@nxp.com> > > Use kmemdup() rather than duplicating its implementation. > > Detected with Coccinelle script. > > Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com> > --- > drivers/crypto/caam/caampkc.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c > index 979072b..c3518ce 100644 > --- a/drivers/crypto/caam/caampkc.c > +++ b/drivers/crypto/caam/caampkc.c > @@ -789,12 +789,10 @@ static inline u8 *caam_read_raw_data(const u8 *buf, size_t *nbytes) > if (!*nbytes) > return NULL; > > - val = kzalloc(*nbytes, GFP_DMA | GFP_KERNEL); > + val = kmemdup(buf, *nbytes, GFP_DMA | GFP_KERNEL); > if (!val) > return NULL; > > - memcpy(val, buf, *nbytes); > - > return val; > } > Hello You could drop also the if (!val) return NULL Regards
On 4/16/2018 5:08 PM, Fabio Estevam wrote: > From: Fabio Estevam <fabio.estevam@nxp.com> > > Use kmemdup() rather than duplicating its implementation. > > Detected with Coccinelle script. > > Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com> > --- > drivers/crypto/caam/caampkc.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c > index 979072b..c3518ce 100644 > --- a/drivers/crypto/caam/caampkc.c > +++ b/drivers/crypto/caam/caampkc.c > @@ -789,12 +789,10 @@ static inline u8 *caam_read_raw_data(const u8 *buf, size_t *nbytes) > if (!*nbytes) > return NULL; > > - val = kzalloc(*nbytes, GFP_DMA | GFP_KERNEL); > + val = kmemdup(buf, *nbytes, GFP_DMA | GFP_KERNEL); > if (!val) > return NULL; > > - memcpy(val, buf, *nbytes); > - > return val; > } Could be further simplified: return kmemdup(...); Horia
diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c index 979072b..c3518ce 100644 --- a/drivers/crypto/caam/caampkc.c +++ b/drivers/crypto/caam/caampkc.c @@ -789,12 +789,10 @@ static inline u8 *caam_read_raw_data(const u8 *buf, size_t *nbytes) if (!*nbytes) return NULL; - val = kzalloc(*nbytes, GFP_DMA | GFP_KERNEL); + val = kmemdup(buf, *nbytes, GFP_DMA | GFP_KERNEL); if (!val) return NULL; - memcpy(val, buf, *nbytes); - return val; }