[PATCH v3] mtd: maps: l440gx: Avoid printing address to dmesg

2019-10-10 Thread Fuqian Huang
Avoid printing the address of l440gx_map.virt every time l440gx init.

Signed-off-by: Fuqian Huang 
---
Changes in v3:
  -- use pr_debug instead of printk(KERN_DEBUG)

 drivers/mtd/maps/l440gx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/maps/l440gx.c b/drivers/mtd/maps/l440gx.c
index 876f12f40018..0eeadfeb620d 100644
--- a/drivers/mtd/maps/l440gx.c
+++ b/drivers/mtd/maps/l440gx.c
@@ -86,7 +86,7 @@ static int __init init_l440gx(void)
return -ENOMEM;
}
simple_map_init(_map);
-   printk(KERN_NOTICE "window_addr = 0x%08lx\n", (unsigned 
long)l440gx_map.virt);
+   pr_debug("window_addr = %p\n", l440gx_map.virt);
 
/* Setup the pm iobase resource
 * This code should move into some kind of generic bridge
-- 
2.11.0



[PATCH v2] mtd: maps: l440gx: Avoid printing address to dmesg

2019-10-10 Thread Fuqian Huang
Avoid printing the address of l440gx_map.virt every time l440gx init.

Signed-off-by: Fuqian Huang 
---
 drivers/mtd/maps/l440gx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/maps/l440gx.c b/drivers/mtd/maps/l440gx.c
index 876f12f40018..ebe37edc8e88 100644
--- a/drivers/mtd/maps/l440gx.c
+++ b/drivers/mtd/maps/l440gx.c
@@ -86,7 +86,7 @@ static int __init init_l440gx(void)
return -ENOMEM;
}
simple_map_init(_map);
-   printk(KERN_NOTICE "window_addr = 0x%08lx\n", (unsigned 
long)l440gx_map.virt);
+   printk(KERN_DEBUG "window_addr = 0x%08lx\n", (unsigned 
long)l440gx_map.virt);
 
/* Setup the pm iobase resource
 * This code should move into some kind of generic bridge
-- 
2.11.0



[PATCH] xen/grant-table: remove unnecessary printing

2019-10-10 Thread Fuqian Huang
xen_auto_xlat_grant_frames.vaddr is definitely NULL in this case.
So the address printing is unnecessary.

Signed-off-by: Fuqian Huang 
---
 drivers/xen/grant-table.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index 7ea6fb6a2e5d..49b381e104ef 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -1363,8 +1363,7 @@ static int gnttab_setup(void)
if (xen_feature(XENFEAT_auto_translated_physmap) && gnttab_shared.addr 
== NULL) {
gnttab_shared.addr = xen_auto_xlat_grant_frames.vaddr;
if (gnttab_shared.addr == NULL) {
-   pr_warn("gnttab share frames (addr=0x%08lx) is not 
mapped!\n",
-   (unsigned 
long)xen_auto_xlat_grant_frames.vaddr);
+   pr_warn("gnttab share frames is not mapped!\n");
return -ENOMEM;
}
}
-- 
2.11.0



[PATCH] mtd: maps: l440gx: Avoid print address to dmesg

2019-10-10 Thread Fuqian Huang
Avoid print the address of l440gx_map.virt every time l440gx init.

Signed-off-by: Fuqian Huang 
---
 drivers/mtd/maps/l440gx.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/mtd/maps/l440gx.c b/drivers/mtd/maps/l440gx.c
index 876f12f40018..e7e40bca82d1 100644
--- a/drivers/mtd/maps/l440gx.c
+++ b/drivers/mtd/maps/l440gx.c
@@ -86,7 +86,6 @@ static int __init init_l440gx(void)
return -ENOMEM;
}
simple_map_init(_map);
-   printk(KERN_NOTICE "window_addr = 0x%08lx\n", (unsigned 
long)l440gx_map.virt);
 
/* Setup the pm iobase resource
 * This code should move into some kind of generic bridge
-- 
2.11.0



[PATCH] m68k: q40: Fix info-leak in rtc_ioctl

2019-09-27 Thread Fuqian Huang
When the option is RTC_PLL_GET, pll will be copied to userland
via copy_to_user. pll is initialized using mach_get_rtc_pll indirect
call and mach_get_rtc_pll is only assigned with function
q40_get_rtc_pll in arch/m68k/q40/config.c.
In function q40_get_rtc_pll, the field pll_ctrl is not initialized.
This will leak uninitialized stack content to userland.
Fix this by zeroing the uninitialized field.

Signed-off-by: Fuqian Huang 
---
 arch/m68k/q40/config.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/m68k/q40/config.c b/arch/m68k/q40/config.c
index e63eb5f06999..f31890078197 100644
--- a/arch/m68k/q40/config.c
+++ b/arch/m68k/q40/config.c
@@ -264,6 +264,7 @@ static int q40_get_rtc_pll(struct rtc_pll_info *pll)
 {
int tmp = Q40_RTC_CTRL;
 
+   pll->pll_ctrl = 0;
pll->pll_value = tmp & Q40_RTC_PLL_MASK;
if (tmp & Q40_RTC_PLL_SIGN)
pll->pll_value = -pll->pll_value;
-- 
2.11.0



Re: [PATCH] KVM: x86: work around leak of uninitialized stack contents

2019-09-12 Thread Fuqian Huang
Vitaly Kuznetsov  於 2019年9月12日週四 下午6:53寫道:
>
> Fuqian Huang  writes:
>
> > Vitaly Kuznetsov  於 2019年9月12日週四 下午4:51寫道:
> >>
> >> Fuqian Huang  writes:
> >>
> >> > Emulation of VMPTRST can incorrectly inject a page fault
> >> > when passed an operand that points to an MMIO address.
> >> > The page fault will use uninitialized kernel stack memory
> >> > as the CR2 and error code.
> >> >
> >> > The right behavior would be to abort the VM with a 
> >> > KVM_EXIT_INTERNAL_ERROR
> >> > exit to userspace;
> >>
> >> Hm, why so? KVM_EXIT_INTERNAL_ERROR is basically an error in KVM, this
> >> is not a proper reaction to a userspace-induced condition (or ever).
> >>
> >> I also looked at VMPTRST's description in Intel's manual and I can't
> >> find and explicit limitation like "this must be normal memory". We're
> >> just supposed to inject #PF "If a page fault occurs in accessing the
> >> memory destination operand."
> >>
> >> In case it seems to be too cumbersome to handle VMPTRST to MMIO and we
> >> think that nobody should be doing that I'd rather prefer injecting #GP.
> >>
> >> Please tell me what I'm missing :-)
> >
> > I found it during the code review, and it looks like the problem the
> > commit 353c0956a618 ("KVM: x86: work around leak of uninitialized
> > stack contents (CVE-2019-7222)")
> > mentions. So I fixed it in a similar way.
> >
>
> Oh, yes, I'm not against the fix at all, I was just wondering about why
> you think we need to kill the guest in this case.

I don't know what is the proper way to handle this case, I just initialize the
memory to avoid information leakage.
(Actually, I am not an expert on KVM's code)
I will be appreciated if the bug is fixed. :)

>
> --
> Vitaly


Re: [PATCH] KVM: x86: work around leak of uninitialized stack contents

2019-09-12 Thread Fuqian Huang
Vitaly Kuznetsov  於 2019年9月12日週四 下午4:51寫道:
>
> Fuqian Huang  writes:
>
> > Emulation of VMPTRST can incorrectly inject a page fault
> > when passed an operand that points to an MMIO address.
> > The page fault will use uninitialized kernel stack memory
> > as the CR2 and error code.
> >
> > The right behavior would be to abort the VM with a KVM_EXIT_INTERNAL_ERROR
> > exit to userspace;
>
> Hm, why so? KVM_EXIT_INTERNAL_ERROR is basically an error in KVM, this
> is not a proper reaction to a userspace-induced condition (or ever).
>
> I also looked at VMPTRST's description in Intel's manual and I can't
> find and explicit limitation like "this must be normal memory". We're
> just supposed to inject #PF "If a page fault occurs in accessing the
> memory destination operand."
>
> In case it seems to be too cumbersome to handle VMPTRST to MMIO and we
> think that nobody should be doing that I'd rather prefer injecting #GP.
>
> Please tell me what I'm missing :-)

I found it during the code review, and it looks like the problem the
commit 353c0956a618 ("KVM: x86: work around leak of uninitialized
stack contents (CVE-2019-7222)")
mentions. So I fixed it in a similar way.

>
> >  however, it is not an easy fix, so for now just ensure
> > that the error code and CR2 are zero.
> >
> > Signed-off-by: Fuqian Huang 
> > ---
> >  arch/x86/kvm/x86.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index 290c3c3efb87..7f442d710858 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -5312,6 +5312,7 @@ int kvm_write_guest_virt_system(struct kvm_vcpu 
> > *vcpu, gva_t addr, void *val,
> >   /* kvm_write_guest_virt_system can pull in tons of pages. */
> >   vcpu->arch.l1tf_flush_l1d = true;
> >
> > + memset(exception, 0, sizeof(*exception));
> >   return kvm_write_guest_virt_helper(addr, val, bytes, vcpu,
> >  PFERR_WRITE_MASK, exception);
> >  }
>
> --
> Vitaly


[PATCH] KVM: x86: work around leak of uninitialized stack contents

2019-09-11 Thread Fuqian Huang
Emulation of VMPTRST can incorrectly inject a page fault
when passed an operand that points to an MMIO address.
The page fault will use uninitialized kernel stack memory
as the CR2 and error code.

The right behavior would be to abort the VM with a KVM_EXIT_INTERNAL_ERROR
exit to userspace; however, it is not an easy fix, so for now just ensure
that the error code and CR2 are zero.

Signed-off-by: Fuqian Huang 
---
 arch/x86/kvm/x86.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 290c3c3efb87..7f442d710858 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5312,6 +5312,7 @@ int kvm_write_guest_virt_system(struct kvm_vcpu *vcpu, 
gva_t addr, void *val,
/* kvm_write_guest_virt_system can pull in tons of pages. */
vcpu->arch.l1tf_flush_l1d = true;
 
+   memset(exception, 0, sizeof(*exception));
return kvm_write_guest_virt_helper(addr, val, bytes, vcpu,
   PFERR_WRITE_MASK, exception);
 }
-- 
2.11.0



[PATCH] mfd: ezx-pcap: replace mutex_lock with spin_lock

2019-08-13 Thread Fuqian Huang
As mutex_lock might sleep.
Function pcap_adc_irq is an interrupt handler.
The use of mutex_lock in pcap_adc_irq may cause sleep
in IRQ context.
Replace mutex_lock with spin_lock to avoid this.

Signed-off-by: Fuqian Huang 
---
 drivers/mfd/ezx-pcap.c | 53 --
 1 file changed, 30 insertions(+), 23 deletions(-)

diff --git a/drivers/mfd/ezx-pcap.c b/drivers/mfd/ezx-pcap.c
index f505e3e1274b..70fa18b04ad2 100644
--- a/drivers/mfd/ezx-pcap.c
+++ b/drivers/mfd/ezx-pcap.c
@@ -35,7 +35,7 @@ struct pcap_chip {
 
/* IO */
u32 buf;
-   struct mutex io_mutex;
+   spinlock_t io_lock;
 
/* IRQ */
unsigned int irq_base;
@@ -48,7 +48,7 @@ struct pcap_chip {
struct pcap_adc_request *adc_queue[PCAP_ADC_MAXQ];
u8 adc_head;
u8 adc_tail;
-   struct mutex adc_mutex;
+   spinlock_t adc_lock;
 };
 
 /* IO */
@@ -76,14 +76,15 @@ static int ezx_pcap_putget(struct pcap_chip *pcap, u32 
*data)
 
 int ezx_pcap_write(struct pcap_chip *pcap, u8 reg_num, u32 value)
 {
+   unsigned long flags;
int ret;
 
-   mutex_lock(>io_mutex);
+   spin_lock_irqsave(>io_lock, flags);
value &= PCAP_REGISTER_VALUE_MASK;
value |= PCAP_REGISTER_WRITE_OP_BIT
| (reg_num << PCAP_REGISTER_ADDRESS_SHIFT);
ret = ezx_pcap_putget(pcap, );
-   mutex_unlock(>io_mutex);
+   spin_unlock_irqrestore(>io_lock, flags);
 
return ret;
 }
@@ -91,14 +92,15 @@ EXPORT_SYMBOL_GPL(ezx_pcap_write);
 
 int ezx_pcap_read(struct pcap_chip *pcap, u8 reg_num, u32 *value)
 {
+   unsigned long flags;
int ret;
 
-   mutex_lock(>io_mutex);
+   spin_lock_irqsave(>io_lock, flags);
*value = PCAP_REGISTER_READ_OP_BIT
| (reg_num << PCAP_REGISTER_ADDRESS_SHIFT);
 
ret = ezx_pcap_putget(pcap, value);
-   mutex_unlock(>io_mutex);
+   spin_unlock_irqrestore(>io_lock, flags);
 
return ret;
 }
@@ -106,11 +108,12 @@ EXPORT_SYMBOL_GPL(ezx_pcap_read);
 
 int ezx_pcap_set_bits(struct pcap_chip *pcap, u8 reg_num, u32 mask, u32 val)
 {
+   unsigned long flags;
int ret;
u32 tmp = PCAP_REGISTER_READ_OP_BIT |
(reg_num << PCAP_REGISTER_ADDRESS_SHIFT);
 
-   mutex_lock(>io_mutex);
+   spin_lock_irqsave(>io_lock, flags);
ret = ezx_pcap_putget(pcap, );
if (ret)
goto out_unlock;
@@ -121,7 +124,7 @@ int ezx_pcap_set_bits(struct pcap_chip *pcap, u8 reg_num, 
u32 mask, u32 val)
 
ret = ezx_pcap_putget(pcap, );
 out_unlock:
-   mutex_unlock(>io_mutex);
+   spin_unlock_irqrestore(>io_lock, flags);
 
return ret;
 }
@@ -212,14 +215,15 @@ static void pcap_irq_handler(struct irq_desc *desc)
 /* ADC */
 void pcap_set_ts_bits(struct pcap_chip *pcap, u32 bits)
 {
+   unsigned long flags;
u32 tmp;
 
-   mutex_lock(>adc_mutex);
+   spin_lock_irqsave(>adc_lock, flags);
ezx_pcap_read(pcap, PCAP_REG_ADC, );
tmp &= ~(PCAP_ADC_TS_M_MASK | PCAP_ADC_TS_REF_LOWPWR);
tmp |= bits & (PCAP_ADC_TS_M_MASK | PCAP_ADC_TS_REF_LOWPWR);
ezx_pcap_write(pcap, PCAP_REG_ADC, tmp);
-   mutex_unlock(>adc_mutex);
+   spin_unlock_irqrestore(>adc_lock, flags);
 }
 EXPORT_SYMBOL_GPL(pcap_set_ts_bits);
 
@@ -234,15 +238,16 @@ static void pcap_disable_adc(struct pcap_chip *pcap)
 
 static void pcap_adc_trigger(struct pcap_chip *pcap)
 {
+   unsigned long flags;
u32 tmp;
u8 head;
 
-   mutex_lock(>adc_mutex);
+   spin_lock_irqsave(>adc_lock, flags);
head = pcap->adc_head;
if (!pcap->adc_queue[head]) {
/* queue is empty, save power */
pcap_disable_adc(pcap);
-   mutex_unlock(>adc_mutex);
+   spin_unlock_irqrestore(>adc_lock, flags);
return;
}
/* start conversion on requested bank, save TS_M bits */
@@ -254,7 +259,7 @@ static void pcap_adc_trigger(struct pcap_chip *pcap)
tmp |= PCAP_ADC_AD_SEL1;
 
ezx_pcap_write(pcap, PCAP_REG_ADC, tmp);
-   mutex_unlock(>adc_mutex);
+   spin_unlock_irqrestore(>adc_lock, flags);
ezx_pcap_write(pcap, PCAP_REG_ADR, PCAP_ADR_ASC);
 }
 
@@ -265,11 +270,11 @@ static irqreturn_t pcap_adc_irq(int irq, void *_pcap)
u16 res[2];
u32 tmp;
 
-   mutex_lock(>adc_mutex);
+   spin_lock(>adc_lock);
req = pcap->adc_queue[pcap->adc_head];
 
if (WARN(!req, "adc irq without pending request\n")) {
-   mutex_unlock(>adc_mutex);
+   spin_unlock(>adc_lock);
return IRQ_HANDLED;
}
 
@@ -285,7 +290,7 @@ static irqreturn_t pcap_adc_irq(int irq, void *_pcap)
 
pcap->adc_queue[pcap->adc_head] = NULL;
pcap->adc_head = (pcap->ad

[PATCH] scsi: lpfc: use spin_lock_irqsave instead of spin_lock_irq in IRQ context

2019-08-12 Thread Fuqian Huang
As spin_unlock_irq will enable interrupts.
Function lpfc_findnode_rpi is called from
lpfc_sli_abts_err_handler (./drivers/scsi/lpfc/lpfc_sli.c)
 <- lpfc_sli_async_event_handler
 <- lpfc_sli_process_unsol_iocb
 <- lpfc_sli_handle_fast_ring_event
 <- lpfc_sli_fp_intr_handler
 <- lpfc_sli_intr_handler
 and lpfc_sli_intr_handler is an interrupt handler.
Interrupts are enabled in interrupt handler.
Use spin_lock_irqsave/spin_unlock_irqrestore instead of spin_(un)lock_irq
in IRQ context to avoid this.

Signed-off-by: Fuqian Huang 
---
 drivers/scsi/lpfc/lpfc_hbadisc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_hbadisc.c b/drivers/scsi/lpfc/lpfc_hbadisc.c
index 28ecaa7fc715..cf02c352b324 100644
--- a/drivers/scsi/lpfc/lpfc_hbadisc.c
+++ b/drivers/scsi/lpfc/lpfc_hbadisc.c
@@ -6065,10 +6065,11 @@ lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t 
rpi)
 {
struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
struct lpfc_nodelist *ndlp;
+   unsigned long flags;
 
-   spin_lock_irq(shost->host_lock);
+   spin_lock_irqsave(shost->host_lock, flags);
ndlp = __lpfc_findnode_rpi(vport, rpi);
-   spin_unlock_irq(shost->host_lock);
+   spin_unlock_irqrestore(shost->host_lock, flags);
return ndlp;
 }
 
-- 
2.11.0



[PATCH v2] net: tundra: tsi108: use spin_lock_irqsave instead of spin_lock_irq in IRQ context

2019-08-08 Thread Fuqian Huang
As spin_unlock_irq will enable interrupts.
Function tsi108_stat_carry is called from interrupt handler tsi108_irq.
Interrupts are enabled in interrupt handler.
Use spin_lock_irqsave/spin_unlock_irqrestore instead of spin_(un)lock_irq
in IRQ context to avoid this.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Preserve reverse christmas tree ordering of local variables.

 drivers/net/ethernet/tundra/tsi108_eth.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/tundra/tsi108_eth.c 
b/drivers/net/ethernet/tundra/tsi108_eth.c
index 78a7de3fb622..c62f474b6d08 100644
--- a/drivers/net/ethernet/tundra/tsi108_eth.c
+++ b/drivers/net/ethernet/tundra/tsi108_eth.c
@@ -371,9 +371,10 @@ tsi108_stat_carry_one(int carry, int carry_bit, int 
carry_shift,
 static void tsi108_stat_carry(struct net_device *dev)
 {
struct tsi108_prv_data *data = netdev_priv(dev);
+   unsigned long flags;
u32 carry1, carry2;
 
-   spin_lock_irq(>misclock);
+   spin_lock_irqsave(>misclock, flags);
 
carry1 = TSI_READ(TSI108_STAT_CARRY1);
carry2 = TSI_READ(TSI108_STAT_CARRY2);
@@ -441,7 +442,7 @@ static void tsi108_stat_carry(struct net_device *dev)
  TSI108_STAT_TXPAUSEDROP_CARRY,
  >tx_pause_drop);
 
-   spin_unlock_irq(>misclock);
+   spin_unlock_irqrestore(>misclock, flags);
 }
 
 /* Read a stat counter atomically with respect to carries.
-- 
2.11.0



[PATCH] scsi: lpfc: remove redundant code

2019-08-07 Thread Fuqian Huang
Remove the redundant initialization code.

Signed-off-by: Fuqian Huang 
---
 drivers/scsi/lpfc/lpfc_bsg.c | 1 -
 drivers/scsi/lpfc/lpfc_sli.c | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index b7216d694bff..5f66a2da2599 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -1571,7 +1571,6 @@ lpfc_issue_ct_rsp(struct lpfc_hba *phba, struct bsg_job 
*job, uint32_t tag,
"2722 Xmit CT response on exchange x%x Data: x%x x%x x%x\n",
icmd->ulpContext, icmd->ulpIoTag, tag, phba->link_state);
 
-   ctiocb->iocb_cmpl = NULL;
ctiocb->iocb_flag |= LPFC_IO_LIBDFC;
ctiocb->vport = phba->pport;
ctiocb->context1 = dd_data;
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index f9e6a135d656..156224c14cc7 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -17445,7 +17445,6 @@ lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport,
icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
ctiocb->context1 = lpfc_nlp_get(ndlp);
 
-   ctiocb->iocb_cmpl = NULL;
ctiocb->vport = phba->pport;
ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
ctiocb->sli4_lxritag = NO_XRI;
-- 
2.11.0



[PATCH] rtc: mxc: use spin_lock_irqsave instead of spin_lock_irq in IRQ context

2019-08-07 Thread Fuqian Huang
As spin_unlock_irq will enable interrupts.
mxc_rtc_irq_enable is called from interrupt handler mxc_rtc_interrupt.
Interrupts are enabled in interrupt handler.
Use spin_lock_irqsave/spin_unlock_irqrestore instead of spin_(un)lock_irq
in IRQ context to avoid this.

Signed-off-by: Fuqian Huang 
---
 drivers/rtc/rtc-mxc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c
index e697e96612bb..902d57dcd0d4 100644
--- a/drivers/rtc/rtc-mxc.c
+++ b/drivers/rtc/rtc-mxc.c
@@ -184,8 +184,9 @@ static void mxc_rtc_irq_enable(struct device *dev, unsigned 
int bit,
struct rtc_plat_data *pdata = dev_get_drvdata(dev);
void __iomem *ioaddr = pdata->ioaddr;
u32 reg;
+   unsigned long flags;
 
-   spin_lock_irq(>rtc->irq_lock);
+   spin_lock_irqsave(>rtc->irq_lock, flags);
reg = readw(ioaddr + RTC_RTCIENR);
 
if (enabled)
@@ -194,7 +195,7 @@ static void mxc_rtc_irq_enable(struct device *dev, unsigned 
int bit,
reg &= ~bit;
 
writew(reg, ioaddr + RTC_RTCIENR);
-   spin_unlock_irq(>rtc->irq_lock);
+   spin_unlock_irqrestore(>rtc->irq_lock, flags);
 }
 
 /* This function is the RTC interrupt service routine. */
-- 
2.11.0



[PATCH] net: tundra: tsi108: use spin_lock_irqsave instead of spin_lock_irq in IRQ context

2019-08-07 Thread Fuqian Huang
As spin_unlock_irq will enable interrupts.
Function tsi108_stat_carry is called from interrupt handler tsi108_irq.
Interrupts are enabled in interrupt handler.
Use spin_lock_irqsave/spin_unlock_irqrestore instead of spin_(un)lock_irq
in IRQ context to avoid this.

Signed-off-by: Fuqian Huang 
---
 drivers/net/ethernet/tundra/tsi108_eth.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/tundra/tsi108_eth.c 
b/drivers/net/ethernet/tundra/tsi108_eth.c
index 78a7de3fb622..14215979d07e 100644
--- a/drivers/net/ethernet/tundra/tsi108_eth.c
+++ b/drivers/net/ethernet/tundra/tsi108_eth.c
@@ -372,8 +372,9 @@ static void tsi108_stat_carry(struct net_device *dev)
 {
struct tsi108_prv_data *data = netdev_priv(dev);
u32 carry1, carry2;
+   unsigned long flags;
 
-   spin_lock_irq(>misclock);
+   spin_lock_irqsave(>misclock, flags);
 
carry1 = TSI_READ(TSI108_STAT_CARRY1);
carry2 = TSI_READ(TSI108_STAT_CARRY2);
@@ -441,7 +442,7 @@ static void tsi108_stat_carry(struct net_device *dev)
  TSI108_STAT_TXPAUSEDROP_CARRY,
  >tx_pause_drop);
 
-   spin_unlock_irq(>misclock);
+   spin_unlock_irqrestore(>misclock, flags);
 }
 
 /* Read a stat counter atomically with respect to carries.
-- 
2.11.0



[PATCH v2] i2c: avoid sleep in IRQ context

2019-08-07 Thread Fuqian Huang
i2c_pxa_handler -> i2c_pxa_irq_txempty ->
i2c_pxa_reset -> i2c_pxa_set_slave -> i2c_pxa_wait_slave

As i2c_pxa_handler is an interrupt handler, it will finally
calls i2c_pxa_wait_slave which calls msleep.

Add in_interrupt check before msleep to avoid sleep
in IRQ context.
When in interrupt context, use mdelay instead of msleep.

Signed-off-by: Fuqian Huang 
---
 drivers/i2c/busses/i2c-pxa.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 2c3c3d6935c0..876e693bafd9 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -456,7 +456,10 @@ static int i2c_pxa_wait_slave(struct pxa_i2c *i2c)
return 1;
}
 
-   msleep(1);
+   if (in_interrupt())
+   mdelay(1);
+   else
+   msleep(1);
}
 
if (i2c_debug > 0)
-- 
2.11.0



Re: [PATCH] i2c: avoid sleep in IRQ context

2019-08-07 Thread Fuqian Huang
Adamski, Krzysztof (Nokia - PL/Wroclaw) 
於 2019年8月7日週三 下午2:51寫道:
>
> On Mon, Aug 05, 2019 at 08:31:34PM +0800, Fuqian Huang wrote:
> >i2c_pxa_handler -> i2c_pxa_irq_txempty ->
> >i2c_pxa_reset -> i2c_pxa_set_slave -> i2c_pxa_wait_slave
> >
> >As i2c_pxa_handler is an interrupt handler, it will finally
> >calls i2c_pxa_wait_slave which calls msleep.
> >
> >Add in_interrupt check before msleep to avoid sleep
> >in IRQ context.
> >
> >Signed-off-by: Fuqian Huang 
> >---
> > drivers/i2c/busses/i2c-pxa.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> >diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
> >index 2c3c3d6935c0..b35a0e8efcb2 100644
> >--- a/drivers/i2c/busses/i2c-pxa.c
> >+++ b/drivers/i2c/busses/i2c-pxa.c
> >@@ -443,6 +443,8 @@ static int i2c_pxa_wait_slave(struct pxa_i2c *i2c)
> >
> >   show_state(i2c);
> >
> >+  if (in_interrupt())
> >+  return 0;
>
> Sleeping in irq context is not good indeed but if you just return here,
> an error will be printed from i2c_pxa_set_slave() and cleanup of ICR
> will be skipped. Is that ok?
Sorry for this mistake.
Maybe it should be changed to mdelay.
And the new patch is like this:
if (in_interrupt()) {
   mdelay(1);
} else {
   msleep(1);
}
>
> >   while (time_before(jiffies, timeout)) {
> >   if (i2c_debug > 1)
> >   dev_dbg(>adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, 
> > IBMR=%02x\n",
>


[PATCH] libata-sff: use spin_lock_irqsave instead of spin_lock_irq in IRQ context.

2019-08-06 Thread Fuqian Huang
Function ata_sff_flush_pio_task use spin_lock_irq/spin_unlock_irq
to protect shared data.
spin_unlock_irq will enable interrupts.

In the interrupt handler nv_swncq_interrupt (./drivers/ata/sata_nv.c),
when ap->link.sactive is true, nv_swncq_host_interrupt was called.
nv_swncq_hotplug is called when NV_SWNCQ_IRQ_HOTPLUG is set.
Then it will follow this chain:
nv_swncq_hotplug -> sata_scr_read (./dirvers/ata/libata-core.c)
 -> sata_pmp_scr_read (./drivers/ata/libata-pmp.c)
 -> sata_pmp_read -> ata_exec_internal 
 -> ata_exec_internal_sg -> ata_sff_flush_pio_task

Interrupts are enabled in interrupt handler.
Use spin_lock_irqsave instead of spin_lock_irq to avoid this.

Signed-off-by: Fuqian Huang 
---
 drivers/ata/libata-sff.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index 10aa27882142..d3143e7e6ec0 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -1241,6 +1241,7 @@ EXPORT_SYMBOL_GPL(ata_sff_queue_pio_task);
 
 void ata_sff_flush_pio_task(struct ata_port *ap)
 {
+   unsigned long flags;
DPRINTK("ENTER\n");
 
cancel_delayed_work_sync(>sff_pio_task);
@@ -1253,9 +1254,9 @@ void ata_sff_flush_pio_task(struct ata_port *ap)
 * __ata_sff_port_intr() checks for HSM_ST_IDLE and before it calls
 * ata_sff_hsm_move() causing ata_sff_hsm_move() to BUG().
 */
-   spin_lock_irq(ap->lock);
+   spin_lock_irqsave(ap->lock, flags);
ap->hsm_task_state = HSM_ST_IDLE;
-   spin_unlock_irq(ap->lock);
+   spin_unlock_irqrestore(ap->lock, flags);
 
ap->sff_pio_task_link = NULL;
 
-- 
2.11.0



[PATCH] sgi-xpc: Use GFP_ATOMIC for kmalloc in atomic context.

2019-08-05 Thread Fuqian Huang
xpc_send_activate_IRQ_uv is called from
 <-xpc_send_activate_IRQ_part_uv
 <-xpc_indicate_partition_disengaged_uv
  (xpc_arch_ops.indicate_partition_disengaged)
 <-xpc_die_deactivate
 <-xpc_system_die

xpc_system_die is registered by atomic_notifier_chain_register,
which indicates xpc_system_die may be called in atomic context.
So the kmalloc in xpc_send_activate_IRQ_uv may be in atomic context.

Use GFP_ATOMIC instead of GFP_KERNEL in kmalloc.

Signed-off-by: Fuqian Huang 
---
 drivers/misc/sgi-xp/xpc_uv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/sgi-xp/xpc_uv.c b/drivers/misc/sgi-xp/xpc_uv.c
index 0c6de97dd347..422341e3234b 100644
--- a/drivers/misc/sgi-xp/xpc_uv.c
+++ b/drivers/misc/sgi-xp/xpc_uv.c
@@ -694,7 +694,7 @@ xpc_send_activate_IRQ_uv(struct xpc_partition *part, void 
*msg, size_t msg_size,
if (gru_mq_desc == NULL) {
gru_mq_desc = kmalloc(sizeof(struct
  gru_message_queue_desc),
- GFP_KERNEL);
+ GFP_ATOMIC);
if (gru_mq_desc == NULL) {
ret = xpNoMemory;
goto done;
-- 
2.11.0



[PATCH] i2c: avoid sleep in IRQ context

2019-08-05 Thread Fuqian Huang
i2c_pxa_handler -> i2c_pxa_irq_txempty ->
i2c_pxa_reset -> i2c_pxa_set_slave -> i2c_pxa_wait_slave

As i2c_pxa_handler is an interrupt handler, it will finally
calls i2c_pxa_wait_slave which calls msleep.

Add in_interrupt check before msleep to avoid sleep
in IRQ context.

Signed-off-by: Fuqian Huang 
---
 drivers/i2c/busses/i2c-pxa.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 2c3c3d6935c0..b35a0e8efcb2 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -443,6 +443,8 @@ static int i2c_pxa_wait_slave(struct pxa_i2c *i2c)
 
show_state(i2c);
 
+   if (in_interrupt())
+   return 0;
while (time_before(jiffies, timeout)) {
if (i2c_debug > 1)
dev_dbg(>adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, 
IBMR=%02x\n",
-- 
2.11.0



Is it safe to kmalloc a large size of memory in interrupt handler?

2019-08-05 Thread Fuqian Huang
In the implementation of kmalloc.
when the allocated size is larger than KMALLOC_MAX_CACHE_SIZE,
it will call kmalloc_large to allocate the memory.
kmalloc_large ->
kmalloc_order_trace->kmalloc_order->alloc_pages->alloc_pages_current->alloc_pages_nodemask->get_page_from_freelist->node_reclaim->__node_reclaim->shrink_node->shrink_node_memcg->get_scan_count

get_scan_count will call spin_unlock_irq which enables local interrupt.
As the local interrupt should be disabled in the interrupt handler.
It is safe to use kmalloc to allocate a large size of memory in
interrupt handler?


Re: [PATCH] drm: use trace_printk rather than printk in drm_dbg.

2019-07-31 Thread Fuqian Huang
Joe Perches  於 2019年7月31日週三 下午2:06寫道:
>
> On Wed, 2019-07-31 at 10:45 +0800, Fuqian Huang wrote:
> > In drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c,
> > amdgpu_ih_process calls DRM_DEBUG which calls drm_dbg and
> > finally calls printk.
> > As amdgpu_ih_process is called from an interrupt handler,
> > and interrupt handler should be short as possible.
> >
> > As printk may lead to bogging down the system or can even
> > create a live lock. printk should not be used in IRQ context.
> > Instead, trace_printk is recommended.
> > Link: https://lwn.net/Articles/365835
> []
> > diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c
> []
> > @@ -236,7 +236,7 @@ void drm_dbg(unsigned int category, const char *format, 
> > ...)
> >   vaf.fmt = format;
> >   vaf.va = 
> >
> > - printk(KERN_DEBUG "[" DRM_NAME ":%ps] %pV",
> > + trace_printk(KERN_DEBUG "[" DRM_NAME ":%ps] %pV",
> >  __builtin_return_address(0), );
> >
> >   va_end(args);
>
> This makes all 4000+ drm_dbg/DRM_DEBUG uses emit
> a trace_printk.
>
> I suggest instead you make only the interrupt uses
> use a different function and not drm_dbg.
>
> Or maybe add an in_interrupt() check like
>
> if (in_interrupt())
> printk(KERN_DEBUG etc...)
> else
> trace_printk(etc...)

I will send a v2 patch to fix this.


[PATCH] dmaengine: pl330: use the same attributes when freeing pl330->mcode_cpu

2019-07-26 Thread Fuqian Huang
In function dmac_alloc_resources(), pl330->mcode_cpu is allocated using
dma_alloc_attrs() but freed with dma_free_coherent().
Use the correct dma_free_attrs() function to free pl330->mcode_cpu.

Signed-off-by: Fuqian Huang 
---
 drivers/dma/pl330.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
index 1163af2ba4a3..6cce9ef61b29 100644
--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -1922,9 +1922,10 @@ static int dmac_alloc_resources(struct pl330_dmac *pl330)
if (ret) {
dev_err(pl330->ddma.dev, "%s:%d Can't to create channels for 
DMAC!\n",
__func__, __LINE__);
-   dma_free_coherent(pl330->ddma.dev,
+   dma_free_attrs(pl330->ddma.dev,
chans * pl330->mcbufsz,
-   pl330->mcode_cpu, pl330->mcode_bus);
+   pl330->mcode_cpu, pl330->mcode_bus,
+   DMA_ATTR_PRIVILEGED);
return ret;
}
 
@@ -2003,9 +2004,9 @@ static void pl330_del(struct pl330_dmac *pl330)
/* Free DMAC resources */
dmac_free_threads(pl330);
 
-   dma_free_coherent(pl330->ddma.dev,
+   dma_free_attrs(pl330->ddma.dev,
pl330->pcfg.num_chan * pl330->mcbufsz, pl330->mcode_cpu,
-   pl330->mcode_bus);
+   pl330->mcode_bus, DMA_ATTR_PRIVILEGED);
 }
 
 /* forward declaration */
-- 
2.11.0



Re: [PATCH v3 15/24] media: exynos4-is: Remove call to memset after dma_alloc_coherent

2019-07-15 Thread Fuqian Huang
Sylwester Nawrocki  於 2019年7月15日週一 下午5:00寫道:
>
> On 7/15/19 05:18, Fuqian Huang wrote:
> > In commit 518a2f1925c3
> > ("dma-mapping: zero memory returned from dma_alloc_*"),
> > dma_alloc_coherent has already zeroed the memory.
> > So memset is not needed
>
> I can't see any changes in the above mentioned commit that would
> make dma_alloc_coherent() (arm_coherent_dma_alloc()) zeroing its
> returned memory. Maybe you need to add a reference to some other
> instead?
>
In the last version patch set, I referenced the commit af7ddd8a627c
("Merge tag 'dma-mapping-4.21' of
git://git.infradead.org/users/hch/dma-mapping")
in the commit log.
The merged commit mentions that
"ensure dma_alloc_coherent returns zeroed memory to
avoid kernel data leaks through userspace.
We already did this for most common architectures,
but this ensures we do it everywhere."
dma_alloc_coherent has already zeroed the memory during allocation
and the commit also deprecates dma_zalloc_coherent.
Greg and other maintainer told me to use the actual commit
rather than the merged commit.
So I reference the commit that ensures the dma_alloc_coherent to
returns zeroed memory every where.
Maybe this belongs to the `most common achitectures` and is not impacted
by the mentioned change.
Should I rewrite the commit log? Just mention that dma_alloc_coherent
has already zeroed the memory and not to reference the commit?


Re: [PATCH v3 04/24] dmaengine: qcom_hidma: Remove call to memset after dmam_alloc_coherent

2019-07-14 Thread Fuqian Huang
Sinan Kaya  於 2019年7月15日週一 下午12:17寫道:
>
> On 7/14/2019 11:17 PM, Fuqian Huang wrote:
> > In commit 518a2f1925c3
> > ("dma-mapping: zero memory returned from dma_alloc_*"),
> > dma_alloc_coherent has already zeroed the memory.
> > So memset is not needed.
> >
> > Signed-off-by: Fuqian Huang 
>
> I don't see SWIO or ARM64 IOMMU drivers getting impacted by
> the mentioned change above (518a2f1925c3).
>
> How does this new behavior apply globally?
>
In the last version patch set, I referenced the commit af7ddd8a627c
("Merge tag 'dma-mapping-4.21' of
git://git.infradead.org/users/hch/dma-mapping")
in the commit log.
The merged commit mentions that
"ensure dma_alloc_coherent returns zeroed memory to
avoid kernel data leaks through userspace.
We already did this for most common architectures,
but this ensures we do it everywhere."
dma_alloc_coherent has already zeroed the memory during allocation
and the commit also deprecates dma_zalloc_coherent.
Greg and other maintainer told me to use the actual commit
rather than the merged commit.
So I reference the commit that ensures the dma_alloc_coherent to
returns zeroed memory every where.
Maybe this belongs to the `most common achitectures` and is not impacted
by the mentioned change.
Should I rewrite the commit log? Just mention that dma_alloc_coherent
has already
zeroed the memory and not to reference the commit?


[PATCH v3 19/24] vmxnet3: Remove call to memset after dma_alloc_coherent

2019-07-14 Thread Fuqian Huang
In commit 518a2f1925c3
("dma-mapping: zero memory returned from dma_alloc_*"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed.

Signed-off-by: Fuqian Huang 
---
Changes in v3:
  - Use actual commit rather than the merge commit in the commit message

 drivers/net/vmxnet3/vmxnet3_drv.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/vmxnet3/vmxnet3_drv.c 
b/drivers/net/vmxnet3/vmxnet3_drv.c
index 3f48f05dd2a6..2a1918f25e47 100644
--- a/drivers/net/vmxnet3/vmxnet3_drv.c
+++ b/drivers/net/vmxnet3/vmxnet3_drv.c
@@ -3430,7 +3430,6 @@ vmxnet3_probe_device(struct pci_dev *pdev,
err = -ENOMEM;
goto err_ver;
}
-   memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
adapter->coal_conf->coalMode = VMXNET3_COALESCE_DISABLED;
adapter->default_coal_mode = true;
}
-- 
2.11.0



[PATCH v3 22/24] tty: serial: Remove call to memset after pci_alloc_consistent

2019-07-14 Thread Fuqian Huang
pci_alloc_consistent calls dma_alloc_coherent directly.
In commit 518a2f1925c3
("dma-mapping: zero memory returned from dma_alloc_*"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed.

Signed-off-by: Fuqian Huang 
---
Changes in v3:
  - Use actual commit rather than the merge commit in the commit message

 drivers/tty/serial/icom.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/tty/serial/icom.c b/drivers/tty/serial/icom.c
index ad374f7c476d..624f3d541c68 100644
--- a/drivers/tty/serial/icom.c
+++ b/drivers/tty/serial/icom.c
@@ -207,8 +207,6 @@ static int get_port_memory(struct icom_port *icom_port)
return -ENOMEM;
}
 
-   memset(icom_port->statStg, 0, 4096);
-
/* FODs: Frame Out Descriptor Queue, this is a FIFO queue that
indicates that frames are to be transmitted
*/
-- 
2.11.0



[PATCH v3 21/24] scsi: Remove redundant memset

2019-07-14 Thread Fuqian Huang
kcalloc already zeros the memory during allocation.
In commit 518a2f1925c3
("dma-mapping: zero memory returned from dma_alloc_*"),
dma_alloc_coherent has already zeroed the memory.
So the memset after these functions is not needed.

Signed-off-by: Fuqian Huang 
---
Changes in v3:
  - Use actual commit rather than the merge commit in the commit message

 drivers/scsi/3w-9xxx.c| 2 --
 drivers/scsi/3w-.c| 2 --
 drivers/scsi/aacraid/rx.c | 1 -
 drivers/scsi/arcmsr/arcmsr_hba.c  | 1 -
 drivers/scsi/be2iscsi/be_iscsi.c  | 1 -
 drivers/scsi/bfa/bfad.c   | 1 -
 drivers/scsi/bnx2fc/bnx2fc_io.c   | 2 --
 drivers/scsi/dpt_i2o.c| 4 
 drivers/scsi/esas2r/esas2r_init.c | 1 -
 drivers/scsi/ips.c| 2 --
 drivers/scsi/lpfc/lpfc_init.c | 2 --
 drivers/scsi/megaraid/megaraid_sas_base.c | 2 --
 drivers/scsi/mpt3sas/mpt3sas_transport.c  | 2 --
 drivers/scsi/mvsas/mv_init.c  | 4 
 drivers/scsi/myrs.c   | 1 -
 drivers/scsi/pmcraid.c| 1 -
 drivers/scsi/qla4xxx/ql4_mbx.c| 1 -
 drivers/scsi/qla4xxx/ql4_os.c | 2 --
 drivers/scsi/qlogicpti.c  | 2 --
 19 files changed, 34 deletions(-)

diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index 3337b1e80412..da17d9104e6b 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -534,8 +534,6 @@ static int twa_allocate_memory(TW_Device_Extension *tw_dev, 
int size, int which)
goto out;
}
 
-   memset(cpu_addr, 0, size*TW_Q_LENGTH);
-
for (i = 0; i < TW_Q_LENGTH; i++) {
switch(which) {
case 0:
diff --git a/drivers/scsi/3w-.c b/drivers/scsi/3w-.c
index 2b1e0d503020..26703ef52a2e 100644
--- a/drivers/scsi/3w-.c
+++ b/drivers/scsi/3w-.c
@@ -848,8 +848,6 @@ static int tw_allocate_memory(TW_Device_Extension *tw_dev, 
int size, int which)
return 1;
}
 
-   memset(cpu_addr, 0, size*TW_Q_LENGTH);
-
for (i=0;ipdev->dev, 512, buffer, baddr);
return ret;
}
-   memset(buffer, 0, 512);
post->Post_Command = cpu_to_le32(COMMAND_POST_RESULTS);
post->Post_Address = cpu_to_le32(baddr);
rx_writel(dev, MUnit.IMRx[0], paddr);
diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 88053b15c363..a0d0dc83184f 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -727,7 +727,6 @@ static int arcmsr_alloc_ccb_pool(struct AdapterControlBlock 
*acb)
}
acb->dma_coherent = dma_coherent;
acb->dma_coherent_handle = dma_coherent_handle;
-   memset(dma_coherent, 0, acb->uncache_size);
acb->ccbsize = roundup_ccbsize;
ccb_tmp = dma_coherent;
curr_phy_upper32 = upper_32_bits(dma_coherent_handle);
diff --git a/drivers/scsi/be2iscsi/be_iscsi.c b/drivers/scsi/be2iscsi/be_iscsi.c
index 2058d50d62e1..09d63bac6d80 100644
--- a/drivers/scsi/be2iscsi/be_iscsi.c
+++ b/drivers/scsi/be2iscsi/be_iscsi.c
@@ -1081,7 +1081,6 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep,
return -ENOMEM;
}
nonemb_cmd.size = req_memsize;
-   memset(nonemb_cmd.va, 0, nonemb_cmd.size);
tag = mgmt_open_connection(phba, dst_addr, beiscsi_ep, _cmd);
if (!tag) {
beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
diff --git a/drivers/scsi/bfa/bfad.c b/drivers/scsi/bfa/bfad.c
index 2f9213b257a4..39ac58337290 100644
--- a/drivers/scsi/bfa/bfad.c
+++ b/drivers/scsi/bfa/bfad.c
@@ -622,7 +622,6 @@ bfad_hal_mem_alloc(struct bfad_s *bfad)
goto ext;
}
dma_elem->dma = phys_addr;
-   memset(dma_elem->kva, 0, dma_elem->mem_len);
}
 ext:
return rc;
diff --git a/drivers/scsi/bnx2fc/bnx2fc_io.c b/drivers/scsi/bnx2fc/bnx2fc_io.c
index 9e50e5b53763..7a10b8738ece 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_io.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_io.c
@@ -614,8 +614,6 @@ int bnx2fc_init_mp_req(struct bnx2fc_cmd *io_req)
bnx2fc_free_mp_resc(io_req);
return FAILED;
}
-   memset(mp_req->req_buf, 0, CNIC_PAGE_SIZE);
-   memset(mp_req->resp_buf, 0, CNIC_PAGE_SIZE);
 
/* Allocate and map mp_req_bd and mp_resp_bd */
sz = sizeof(struct fcoe_bd_ctx);
diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index abc74fd474dc..b1b879beebfb 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -1331,7 +1331,6 @@ static s32 adpt_i2o_reset_hba(adpt_hba* pHba)
printk(KERN_ERR"IOP reset failed - no free memory.\n");
return -ENOMEM;
}
-   memset(sta

[PATCH v3 16/24] scsi: mptfusion: Remove call to memset after pci_alloc_consistent

2019-07-14 Thread Fuqian Huang
pci_alloc_consistent calls dma_alloc_coherent directly.
In commit 518a2f1925c3
("dma-mapping: zero memory returned from dma_alloc_*"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed

Signed-off-by: Fuqian Huang 
---
Changes in v3:
  - Use actual commit rather than the merge commit in the commit message

 drivers/message/fusion/mptbase.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index c2dd322691d1..3eeb4cbdaf3b 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -4507,7 +4507,6 @@ PrimeIocFifos(MPT_ADAPTER *ioc)
dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Total alloc @ 
%p[%p], sz=%d[%x] bytes\n",
ioc->name, mem, (void *)(ulong)alloc_dma, 
total_size, total_size));
 
-   memset(mem, 0, total_size);
ioc->alloc_total += total_size;
ioc->alloc = mem;
ioc->alloc_dma = alloc_dma;
-- 
2.11.0



[PATCH v3 17/24] ethernet: remove redundant memset

2019-07-14 Thread Fuqian Huang
kvzalloc already zeroes the memory during the allocation.
pci_alloc_consistent calls dma_alloc_coherent directly.
In commit 518a2f1925c3
("dma-mapping: zero memory returned from dma_alloc_*"),
dma_alloc_coherent has already zeroed the memory.
So the memset after these function is not needed.

Signed-off-by: Fuqian Huang 
---
Changes in v3:
  - Use actual commit rather than the merge commit in the commit message

 drivers/net/ethernet/atheros/atlx/atl1.c   | 2 --
 drivers/net/ethernet/atheros/atlx/atl2.c   | 1 -
 drivers/net/ethernet/broadcom/bnxt/bnxt.c  | 2 --
 drivers/net/ethernet/chelsio/cxgb4/sched.c | 1 -
 drivers/net/ethernet/freescale/fec_main.c  | 2 --
 drivers/net/ethernet/jme.c | 5 -
 drivers/net/ethernet/marvell/skge.c| 2 --
 drivers/net/ethernet/mellanox/mlx4/eq.c| 2 --
 drivers/net/ethernet/mellanox/mlx5/core/eswitch.c  | 1 -
 drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c | 3 ---
 drivers/net/ethernet/mellanox/mlxsw/pci.c  | 1 -
 drivers/net/ethernet/neterion/s2io.c   | 1 -
 drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c| 3 ---
 drivers/net/ethernet/ti/tlan.c | 1 -
 14 files changed, 27 deletions(-)

diff --git a/drivers/net/ethernet/atheros/atlx/atl1.c 
b/drivers/net/ethernet/atheros/atlx/atl1.c
index 7c767ce9aafa..b5c6dc914720 100644
--- a/drivers/net/ethernet/atheros/atlx/atl1.c
+++ b/drivers/net/ethernet/atheros/atlx/atl1.c
@@ -1060,8 +1060,6 @@ static s32 atl1_setup_ring_resources(struct atl1_adapter 
*adapter)
goto err_nomem;
}
 
-   memset(ring_header->desc, 0, ring_header->size);
-
/* init TPD ring */
tpd_ring->dma = ring_header->dma;
offset = (tpd_ring->dma & 0x7) ? (8 - (ring_header->dma & 0x7)) : 0;
diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c 
b/drivers/net/ethernet/atheros/atlx/atl2.c
index 3a3fb5ce0fee..3aba38322717 100644
--- a/drivers/net/ethernet/atheros/atlx/atl2.c
+++ b/drivers/net/ethernet/atheros/atlx/atl2.c
@@ -291,7 +291,6 @@ static s32 atl2_setup_ring_resources(struct atl2_adapter 
*adapter)
>ring_dma);
if (!adapter->ring_vir_addr)
return -ENOMEM;
-   memset(adapter->ring_vir_addr, 0, adapter->ring_size);
 
/* Init TXD Ring */
adapter->txd_dma = adapter->ring_dma ;
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c 
b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 3f632028eff0..1069eb01cc55 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -2677,8 +2677,6 @@ static int bnxt_alloc_tx_rings(struct bnxt *bp)
mapping = txr->tx_push_mapping +
sizeof(struct tx_push_bd);
txr->data_mapping = cpu_to_le64(mapping);
-
-   memset(txr->tx_push, 0, sizeof(struct tx_push_bd));
}
qidx = bp->tc_to_qidx[j];
ring->queue_id = bp->q_info[qidx].queue_id;
diff --git a/drivers/net/ethernet/chelsio/cxgb4/sched.c 
b/drivers/net/ethernet/chelsio/cxgb4/sched.c
index ba6c153ee45c..60218dc676a8 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/sched.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/sched.c
@@ -207,7 +207,6 @@ static int t4_sched_queue_bind(struct port_info *pi, struct 
ch_sched_queue *p)
goto out_err;
 
/* Bind queue to specified class */
-   memset(qe, 0, sizeof(*qe));
qe->cntxt_id = qid;
memcpy(>param, p, sizeof(qe->param));
 
diff --git a/drivers/net/ethernet/freescale/fec_main.c 
b/drivers/net/ethernet/freescale/fec_main.c
index 9d459ccf251d..e5610a4da539 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -3144,8 +3144,6 @@ static int fec_enet_init(struct net_device *ndev)
return -ENOMEM;
}
 
-   memset(cbd_base, 0, bd_size);
-
/* Get the Ethernet address */
fec_get_mac(ndev);
/* make sure MAC we just acquired is programmed into the hw */
diff --git a/drivers/net/ethernet/jme.c b/drivers/net/ethernet/jme.c
index 76b7b7b85e35..0b668357db4d 100644
--- a/drivers/net/ethernet/jme.c
+++ b/drivers/net/ethernet/jme.c
@@ -582,11 +582,6 @@ jme_setup_tx_resources(struct jme_adapter *jme)
if (unlikely(!(txring->bufinf)))
goto err_free_txring;
 
-   /*
-* Initialize Transmit Descriptors
-*/
-   memset(txring->alloc, 0, TX_RING_ALLOC_SIZE(jme->tx_ring_size));
-
return 0;
 
 err_free_txring:
diff --git a/drivers/net/ethernet/marvell/skge.c 
b/drivers/net/ethernet/marvell/skge.c
index 35a92fd2cf39..9ac854c2b371 100644
--- a/driver

[PATCH v3 15/24] media: exynos4-is: Remove call to memset after dma_alloc_coherent

2019-07-14 Thread Fuqian Huang
In commit 518a2f1925c3
("dma-mapping: zero memory returned from dma_alloc_*"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed

Signed-off-by: Fuqian Huang 
---
Changes in v3:
  - Use actual commit rather than the merge commit in the commit message

 drivers/media/platform/exynos4-is/fimc-is.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/media/platform/exynos4-is/fimc-is.c 
b/drivers/media/platform/exynos4-is/fimc-is.c
index e043d55133a3..77633e356305 100644
--- a/drivers/media/platform/exynos4-is/fimc-is.c
+++ b/drivers/media/platform/exynos4-is/fimc-is.c
@@ -341,7 +341,6 @@ static int fimc_is_alloc_cpu_memory(struct fimc_is *is)
return -ENOMEM;
 
is->memory.size = FIMC_IS_CPU_MEM_SIZE;
-   memset(is->memory.vaddr, 0, is->memory.size);
 
dev_info(dev, "FIMC-IS CPU memory base: %#x\n", (u32)is->memory.paddr);
 
-- 
2.11.0



[PATCH v3 13/24] IB/ipoib: remove unneeded memset

2019-07-14 Thread Fuqian Huang
vzalloc has already zeroed the memory during the allocation.
So memset is unneeded.

Signed-off-by: Fuqian Huang 
---
 drivers/infiniband/ulp/ipoib/ipoib_cm.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/infiniband/ulp/ipoib/ipoib_cm.c 
b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
index aa9dcfc36cd3..c59e00a0881f 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
@@ -1153,7 +1153,6 @@ static int ipoib_cm_tx_init(struct ipoib_cm_tx *p, u32 
qpn,
ret = -ENOMEM;
goto err_tx;
}
-   memset(p->tx_ring, 0, ipoib_sendq_size * sizeof(*p->tx_ring));
 
p->qp = ipoib_cm_create_tx_qp(p->dev, p);
memalloc_noio_restore(noio_flag);
-- 
2.11.0



[PATCH v3 18/24] hippi: Remove call to memset after pci_alloc_consistent

2019-07-14 Thread Fuqian Huang
pci_alloc_consistent calls dma_alloc_coherent directly.
In commit 518a2f1925c3
("dma-mapping: zero memory returned from dma_alloc_*"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed.

Signed-off-by: Fuqian Huang 
---
Changes in v3:
  - Use actual commit rather than the merge commit in the commit message

 drivers/net/hippi/rrunner.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/net/hippi/rrunner.c b/drivers/net/hippi/rrunner.c
index 7b9350dbebdd..2a6ec5394966 100644
--- a/drivers/net/hippi/rrunner.c
+++ b/drivers/net/hippi/rrunner.c
@@ -1196,7 +1196,6 @@ static int rr_open(struct net_device *dev)
goto error;
}
rrpriv->rx_ctrl_dma = dma_addr;
-   memset(rrpriv->rx_ctrl, 0, 256*sizeof(struct ring_ctrl));
 
rrpriv->info = pci_alloc_consistent(pdev, sizeof(struct rr_info),
_addr);
@@ -1205,7 +1204,6 @@ static int rr_open(struct net_device *dev)
goto error;
}
rrpriv->info_dma = dma_addr;
-   memset(rrpriv->info, 0, sizeof(struct rr_info));
wmb();
 
spin_lock_irqsave(>lock, flags);
-- 
2.11.0



[PATCH v3 11/24] RDMA/nes: Remove call to memset after pci_alloc_consistent

2019-07-14 Thread Fuqian Huang
pci_alloc_consitent calls dma_alloc_coherent directly.
In commit 518a2f1925c3
("dma-mapping: zero memory returned from dma_alloc_*"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed.

Signed-off-by: Fuqian Huang 
---
Changes in v3:
  - Use actual commit rather than the merge commit in the commit message

 drivers/infiniband/hw/nes/nes_verbs.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/infiniband/hw/nes/nes_verbs.c 
b/drivers/infiniband/hw/nes/nes_verbs.c
index 49024326a518..534f978f1a58 100644
--- a/drivers/infiniband/hw/nes/nes_verbs.c
+++ b/drivers/infiniband/hw/nes/nes_verbs.c
@@ -828,7 +828,6 @@ static int nes_setup_virt_qp(struct nes_qp *nesqp, struct 
nes_pbl *nespbl,
kunmap(nesqp->page);
return -ENOMEM;
}
-   memset(nesqp->pbl_vbase, 0, 256);
/* fill in the page address in the pbl buffer.. */
tpbl = pblbuffer + 16;
pbl = (__le64 *)nespbl->pbl_vbase;
@@ -898,8 +897,6 @@ static int nes_setup_mmap_qp(struct nes_qp *nesqp, struct 
nes_vnic *nesvnic,
"host descriptor rings located @ %p (pa = 0x%08lX.) 
size = %u.\n",
mem, (unsigned long)nesqp->hwqp.sq_pbase, 
nesqp->qp_mem_size);
 
-   memset(mem, 0, nesqp->qp_mem_size);
-
nesqp->hwqp.sq_vbase = mem;
mem += sizeof(struct nes_hw_qp_wqe) * sq_size;
 
-- 
2.11.0



[PATCH v3 14/24] media: ngene: Remove call to memset after pci_alloc_consistent

2019-07-14 Thread Fuqian Huang
pci_alloc_consistent calls dma_alloc_coherent directly.
In commit 518a2f1925c3
("dma-mapping: zero memory returned from dma_alloc_*"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed.

Signed-off-by: Fuqian Huang 
---
Changes in v3:
  - Use actual commit rather than the merge commit in the commit message

 drivers/media/pci/ngene/ngene-core.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/media/pci/ngene/ngene-core.c 
b/drivers/media/pci/ngene/ngene-core.c
index b75ab7d29226..af15ca1c501b 100644
--- a/drivers/media/pci/ngene/ngene-core.c
+++ b/drivers/media/pci/ngene/ngene-core.c
@@ -854,8 +854,6 @@ static int create_ring_buffer(struct pci_dev *pci_dev,
if (!Head)
return -ENOMEM;
 
-   memset(Head, 0, MemSize);
-
PARingBufferCur = PARingBufferHead;
Cur = Head;
 
@@ -907,8 +905,6 @@ static int AllocateRingBuffers(struct pci_dev *pci_dev,
if (SCListMem == NULL)
return -ENOMEM;
 
-   memset(SCListMem, 0, SCListMemSize);
-
pRingBuffer->SCListMem = SCListMem;
pRingBuffer->PASCListMem = PASCListMem;
pRingBuffer->SCListMemSize = SCListMemSize;
-- 
2.11.0



[PATCH v3 10/24] IB/mthca: Remove call to memset after dma_alloc_coherent

2019-07-14 Thread Fuqian Huang
In commit 518a2f1925c3
("dma-mapping: zero memory returned from dma_alloc_*"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed.

Signed-off-by: Fuqian Huang 
---
Changes in v3:
  - Use actual commit rather than the merge commit in the commit message

 drivers/infiniband/hw/mthca/mthca_allocator.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/infiniband/hw/mthca/mthca_allocator.c 
b/drivers/infiniband/hw/mthca/mthca_allocator.c
index aaf10dd5364d..aef1d274a14e 100644
--- a/drivers/infiniband/hw/mthca/mthca_allocator.c
+++ b/drivers/infiniband/hw/mthca/mthca_allocator.c
@@ -214,8 +214,6 @@ int mthca_buf_alloc(struct mthca_dev *dev, int size, int 
max_direct,
 
dma_unmap_addr_set(>direct, mapping, t);
 
-   memset(buf->direct.buf, 0, size);
-
while (t & ((1 << shift) - 1)) {
--shift;
npages *= 2;
-- 
2.11.0



[PATCH v3 09/24] rdma/hns: Remove call to memset after dma_alloc_coherent

2019-07-14 Thread Fuqian Huang
In commit 518a2f1925c3
("dma-mapping: zero memory returned from dma_alloc_*"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed.

Signed-off-by: Fuqian Huang 
---
Changes in v3:
  - Use actual commit rather than the merge commit in the commit message

 drivers/infiniband/hw/hns/hns_roce_hw_v1.c | 1 -
 drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 3 ---
 2 files changed, 4 deletions(-)

diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c 
b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
index 3afd3e9330e7..a43464e292b6 100644
--- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
+++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
@@ -4265,7 +4265,6 @@ static int hns_roce_v1_create_eq(struct hns_roce_dev 
*hr_dev,
}
 
eq->buf_list[i].map = tmp_dma_addr;
-   memset(eq->buf_list[i].buf, 0, HNS_ROCE_BA_SIZE);
}
eq->cons_index = 0;
roce_set_field(tmp, ROCEE_CAEP_AEQC_AEQE_SHIFT_CAEP_AEQC_STATE_M,
diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c 
b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
index b5392cb5b20f..a4a7c5962916 100644
--- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
+++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
@@ -1774,7 +1774,6 @@ static int hns_roce_init_link_table(struct hns_roce_dev 
*hr_dev,
goto err_alloc_buf_failed;
 
link_tbl->pg_list[i].map = t;
-   memset(link_tbl->pg_list[i].buf, 0, buf_chk_sz);
 
entry[i].blk_ba0 = (t >> 12) & 0x;
roce_set_field(entry[i].blk_ba1_nxt_ptr,
@@ -5387,8 +5386,6 @@ static int hns_roce_mhop_alloc_eq(struct hns_roce_dev 
*hr_dev,
eq->cur_eqe_ba = eq->l0_dma;
eq->nxt_eqe_ba = 0;
 
-   memset(eq->bt_l0, 0, eq->entries * eq->eqe_size);
-
return 0;
}
 
-- 
2.11.0



[PATCH v3 12/24] RDMA/ocrdma: Remove call to memset after dma_alloc_coherent

2019-07-14 Thread Fuqian Huang
In commit 518a2f1925c3
("dma-mapping: zero memory returned from dma_alloc_*"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed.

Signed-off-by: Fuqian Huang 
---
Changes in v3:
  - Use actual commit rather than the merge commit in the commit message

 drivers/infiniband/hw/ocrdma/ocrdma_hw.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c 
b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
index 5127e2ea4bdd..6e07712eb3ed 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
@@ -1351,7 +1351,6 @@ static int ocrdma_mbx_get_ctrl_attribs(struct ocrdma_dev 
*dev)
mqe->u.nonemb_req.sge[0].pa_hi = (u32) upper_32_bits(dma.pa);
mqe->u.nonemb_req.sge[0].len = dma.size;
 
-   memset(dma.va, 0, dma.size);
ocrdma_init_mch((struct ocrdma_mbx_hdr *)dma.va,
OCRDMA_CMD_GET_CTRL_ATTRIBUTES,
OCRDMA_SUBSYS_COMMON,
@@ -1690,7 +1689,6 @@ static int ocrdma_mbx_create_ah_tbl(struct ocrdma_dev 
*dev)
goto mem_err_ah;
dev->av_tbl.pa = pa;
dev->av_tbl.num_ah = max_ah;
-   memset(dev->av_tbl.va, 0, dev->av_tbl.size);
 
pbes = (struct ocrdma_pbe *)dev->av_tbl.pbl.va;
for (i = 0; i < dev->av_tbl.size / OCRDMA_MIN_Q_PAGE_SIZE; i++) {
@@ -2905,7 +2903,6 @@ static int ocrdma_mbx_get_dcbx_config(struct ocrdma_dev 
*dev, u32 ptype,
mqe_sge->pa_hi = (u32) upper_32_bits(pa);
mqe_sge->len = cmd.hdr.pyld_len;
 
-   memset(req, 0, sizeof(struct ocrdma_get_dcbx_cfg_req));
ocrdma_init_mch(>hdr, OCRDMA_CMD_GET_DCBX_CONFIG,
OCRDMA_SUBSYS_DCBX, cmd.hdr.pyld_len);
req->param_type = ptype;
-- 
2.11.0



[PATCH v3 08/24] rdma/cxgb4: Remove call to memset after dma_alloc_coherent

2019-07-14 Thread Fuqian Huang
In commit 518a2f1925c3
("dma-mapping: zero memory returned from dma_alloc_*"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed.

Signed-off-by: Fuqian Huang 
---
Changes in v3:
  - Use actual commit rather than the merge commit in the commit message

 drivers/infiniband/hw/cxgb4/cq.c | 1 -
 drivers/infiniband/hw/cxgb4/qp.c | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/infiniband/hw/cxgb4/cq.c b/drivers/infiniband/hw/cxgb4/cq.c
index 52ce586621c6..fcd161e3495b 100644
--- a/drivers/infiniband/hw/cxgb4/cq.c
+++ b/drivers/infiniband/hw/cxgb4/cq.c
@@ -104,7 +104,6 @@ static int create_cq(struct c4iw_rdev *rdev, struct t4_cq 
*cq,
goto err3;
}
dma_unmap_addr_set(cq, mapping, cq->dma_addr);
-   memset(cq->queue, 0, cq->memsize);
 
if (user && ucontext->is_32b_cqe) {
cq->qp_errp = &((struct t4_status_page *)
diff --git a/drivers/infiniband/hw/cxgb4/qp.c b/drivers/infiniband/hw/cxgb4/qp.c
index e92b9544357a..4882dcbb7d20 100644
--- a/drivers/infiniband/hw/cxgb4/qp.c
+++ b/drivers/infiniband/hw/cxgb4/qp.c
@@ -274,7 +274,6 @@ static int create_qp(struct c4iw_rdev *rdev, struct t4_wq 
*wq,
 (unsigned long long)virt_to_phys(wq->sq.queue),
 wq->rq.queue,
 (unsigned long long)virt_to_phys(wq->rq.queue));
-   memset(wq->rq.queue, 0, wq->rq.memsize);
dma_unmap_addr_set(>rq, mapping, wq->rq.dma_addr);
}
 
-- 
2.11.0



[PATCH v3 06/24] i2c: ismt: Remove call to memset after dmam_alloc_coherent

2019-07-14 Thread Fuqian Huang
In commit 518a2f1925c3
("dma-mapping: zero memory returned from dma_alloc_*"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed.

Acked-by: Neil Horman 
Signed-off-by: Fuqian Huang 
---
Changes in v3:
  - Use actual commit rather than the merge commit in the commit message

 drivers/i2c/busses/i2c-ismt.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-ismt.c b/drivers/i2c/busses/i2c-ismt.c
index 02d23edb2fb1..2f95e25a10f7 100644
--- a/drivers/i2c/busses/i2c-ismt.c
+++ b/drivers/i2c/busses/i2c-ismt.c
@@ -781,8 +781,6 @@ static int ismt_dev_init(struct ismt_priv *priv)
if (!priv->hw)
return -ENOMEM;
 
-   memset(priv->hw, 0, (ISMT_DESC_ENTRIES * sizeof(struct ismt_desc)));
-
priv->head = 0;
init_completion(>cmp);
 
-- 
2.11.0



[PATCH v3 07/24] rdma/cxgb3: Remove call to memset after dma_alloc_coherent

2019-07-14 Thread Fuqian Huang
In commit 518a2f1925c3
("dma-mapping: zero memory returned from dma_alloc_*"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed.

Signed-off-by: Fuqian Huang 
---
Changes in v3:
  - Use actual commit rather than the merge commit in the commit message

 drivers/infiniband/hw/cxgb3/cxio_hal.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/infiniband/hw/cxgb3/cxio_hal.c 
b/drivers/infiniband/hw/cxgb3/cxio_hal.c
index 8ac72ac7cbac..0e37f55678f8 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_hal.c
+++ b/drivers/infiniband/hw/cxgb3/cxio_hal.c
@@ -174,7 +174,6 @@ int cxio_create_cq(struct cxio_rdev *rdev_p, struct t3_cq 
*cq, int kernel)
return -ENOMEM;
}
dma_unmap_addr_set(cq, mapping, cq->dma_addr);
-   memset(cq->queue, 0, size);
setup.id = cq->cqid;
setup.base_addr = (u64) (cq->dma_addr);
setup.size = 1UL << cq->size_log2;
@@ -538,8 +537,6 @@ static int cxio_hal_init_ctrl_qp(struct cxio_rdev *rdev_p)
dma_unmap_addr_set(_p->ctrl_qp, mapping,
   rdev_p->ctrl_qp.dma_addr);
rdev_p->ctrl_qp.doorbell = (void __iomem *)rdev_p->rnic_info.kdb_addr;
-   memset(rdev_p->ctrl_qp.workq, 0,
-  (1 << T3_CTRL_QP_SIZE_LOG2) * sizeof(union t3_wr));
 
mutex_init(_p->ctrl_qp.lock);
init_waitqueue_head(_p->ctrl_qp.waitq);
-- 
2.11.0



[PATCH v3 01/24] sh: mm: Remove call to memset after dma_alloc_coherent

2019-07-14 Thread Fuqian Huang
In commit 518a2f1925c3
("dma-mapping: zero memory returned from dma_alloc_*"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed.

Signed-off-by: Fuqian Huang 
---
Changes in v3:
  - Use actual commit rather than the merge commit in the commit message

 arch/sh/mm/consistent.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/arch/sh/mm/consistent.c b/arch/sh/mm/consistent.c
index 792f36129062..b09510adfae9 100644
--- a/arch/sh/mm/consistent.c
+++ b/arch/sh/mm/consistent.c
@@ -58,8 +58,6 @@ int __init platform_resource_setup_memory(struct 
platform_device *pdev,
return -ENOMEM;
}
 
-   memset(buf, 0, memsize);
-
r->flags = IORESOURCE_MEM;
r->start = dma_handle;
r->end = r->start + memsize - 1;
-- 
2.11.0



[PATCH v3 02/24] atm: idt77252: Remove call to memset after dma_alloc_coherent

2019-07-14 Thread Fuqian Huang
In commit 518a2f1925c3
("dma-mapping: zero memory returned from dma_alloc_*"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed.

Signed-off-by: Fuqian Huang 
---
Changes in v3:
  - Use actual commit rather than the merge commit in the commit message

 drivers/atm/idt77252.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
index 43a14579e80e..df51680e8931 100644
--- a/drivers/atm/idt77252.c
+++ b/drivers/atm/idt77252.c
@@ -1379,7 +1379,6 @@ init_tsq(struct idt77252_dev *card)
printk("%s: can't allocate TSQ.\n", card->name);
return -1;
}
-   memset(card->tsq.base, 0, TSQSIZE);
 
card->tsq.last = card->tsq.base + TSQ_NUM_ENTRIES - 1;
card->tsq.next = card->tsq.last;
-- 
2.11.0



[PATCH v3 03/24] dmaengine: imx-sdma: Remove call to memset after dma_alloc_coherent

2019-07-14 Thread Fuqian Huang
In commit 518a2f1925c3
("dma-mapping: zero memory returned from dma_alloc_*"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed.

Signed-off-by: Fuqian Huang 
---
Changes in v3:
  - Use actual commit rather than the merge commit in the commit message

 drivers/dma/imx-sdma.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 4ec84a633bd3..decfb9e9648a 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -1886,10 +1886,6 @@ static int sdma_init(struct sdma_engine *sdma)
sdma->context_phys = ccb_phys +
MAX_DMA_CHANNELS * sizeof (struct sdma_channel_control);
 
-   /* Zero-out the CCB structures array just allocated */
-   memset(sdma->channel_control, 0,
-   MAX_DMA_CHANNELS * sizeof (struct 
sdma_channel_control));
-
/* disable all channels */
for (i = 0; i < sdma->drvdata->num_events; i++)
writel_relaxed(0, sdma->regs + chnenbl_ofs(sdma, i));
-- 
2.11.0



[PATCH v3 04/24] dmaengine: qcom_hidma: Remove call to memset after dmam_alloc_coherent

2019-07-14 Thread Fuqian Huang
In commit 518a2f1925c3
("dma-mapping: zero memory returned from dma_alloc_*"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed.

Signed-off-by: Fuqian Huang 
---
Changes in v3:
  - Use actual commit rather than the merge commit in the commit message

 drivers/dma/qcom/hidma_ll.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/dma/qcom/hidma_ll.c b/drivers/dma/qcom/hidma_ll.c
index 5bf8b145c427..bb4471e84e48 100644
--- a/drivers/dma/qcom/hidma_ll.c
+++ b/drivers/dma/qcom/hidma_ll.c
@@ -749,7 +749,6 @@ struct hidma_lldev *hidma_ll_init(struct device *dev, u32 
nr_tres,
if (!lldev->tre_ring)
return NULL;
 
-   memset(lldev->tre_ring, 0, (HIDMA_TRE_SIZE + 1) * nr_tres);
lldev->tre_ring_size = HIDMA_TRE_SIZE * nr_tres;
lldev->nr_tres = nr_tres;
 
@@ -769,7 +768,6 @@ struct hidma_lldev *hidma_ll_init(struct device *dev, u32 
nr_tres,
if (!lldev->evre_ring)
return NULL;
 
-   memset(lldev->evre_ring, 0, (HIDMA_EVRE_SIZE + 1) * nr_tres);
lldev->evre_ring_size = HIDMA_EVRE_SIZE * nr_tres;
 
/* the EVRE ring has to be EVRE_SIZE aligned */
-- 
2.11.0



[PATCH 2/2] dmaengine: pl330: use the same attriobutes when freeing pl330->mcode_cpu

2019-07-10 Thread Fuqian Huang
In function dmac_alloc_recources(), pl330->mcode_cpu is allocated using
dma_alloc_attrs() but freed with dma_free_coherent().
Use the correct dma_free_attrs() function to free pl330->mcode_cpu.

Signed-off-by: Fuqian Huang 
---
 drivers/dma/pl330.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
index 56f9fabc99c4..d9c6ae0732c6 100644
--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -1918,9 +1918,10 @@ static int dmac_alloc_resources(struct pl330_dmac *pl330)
if (ret) {
dev_err(pl330->ddma.dev, "%s:%d Can't to create channels for 
DMAC!\n",
__func__, __LINE__);
-   dma_free_coherent(pl330->ddma.dev,
+   dma_free_attrs(pl330->ddma.dev,
chans * pl330->mcbufsz,
-   pl330->mcode_cpu, pl330->mcode_bus);
+   pl330->mcode_cpu, pl330->mcode_bus,
+   DMA_ATTR_PRIVILEGED);
return ret;
}
 
@@ -1999,9 +2000,9 @@ static void pl330_del(struct pl330_dmac *pl330)
/* Free DMAC resources */
dmac_free_threads(pl330);
 
-   dma_free_coherent(pl330->ddma.dev,
+   dma_free_attrs(pl330->ddma.dev,
pl330->pcfg.num_chan * pl330->mcbufsz, pl330->mcode_cpu,
-   pl330->mcode_bus);
+   pl330->mcode_bus, DMA_ATTR_PRIVILEGED);
 }
 
 /* forward declaration */
-- 
2.11.0



[PATCH 1/2] drm/ttm: use the same attributes when freeing d_page->vaddr

2019-07-10 Thread Fuqian Huang
In function __ttm_dma_alloc_page(), d_page->addr is allocated
by dma_alloc_attrs() but freed with use dma_free_coherent() in
__ttm_dma_free_page().
Use the correct dma_free_attrs() to free d_page->vaddr.

Signed-off-by: Fuqian Huang 
---
 drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c 
b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
index d594f7520b7b..7d78e6deac89 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
@@ -285,9 +285,13 @@ static int ttm_set_pages_caching(struct dma_pool *pool,
 
 static void __ttm_dma_free_page(struct dma_pool *pool, struct dma_page *d_page)
 {
+   unsigned long attrs = 0;
dma_addr_t dma = d_page->dma;
d_page->vaddr &= ~VADDR_FLAG_HUGE_POOL;
-   dma_free_coherent(pool->dev, pool->size, (void *)d_page->vaddr, dma);
+   if (pool->type & IS_HUGE)
+   attrs = DMA_ATTR_NO_WARN;
+
+   dma_free_attrs(pool->dev, pool->size, (void *)d_page->vaddr, dma, 
attrs);
 
kfree(d_page);
d_page = NULL;
-- 
2.11.0



[PATCH 14/14] net: phy: Make use of linkmode_mod_bit helper

2019-07-08 Thread Fuqian Huang
linkmode_mod_bit is introduced as a helper function to set/clear
bits in a linkmode.
Replace the if else code structure with a call to the helper
linkmode_mod_bit.

Signed-off-by: Fuqian Huang 
---
 drivers/net/phy/phy.c | 16 
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index e8885429293a..75b8e5aff747 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -297,12 +297,8 @@ int phy_ethtool_sset(struct phy_device *phydev, struct 
ethtool_cmd *cmd)
 
linkmode_copy(phydev->advertising, advertising);
 
-   if (AUTONEG_ENABLE == cmd->autoneg)
-   linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
-phydev->advertising);
-   else
-   linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
-  phydev->advertising);
+   linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
+phydev->advertising, AUTONEG_ENABLE == cmd->autoneg);
 
phydev->duplex = cmd->duplex;
 
@@ -352,12 +348,8 @@ int phy_ethtool_ksettings_set(struct phy_device *phydev,
 
linkmode_copy(phydev->advertising, advertising);
 
-   if (autoneg == AUTONEG_ENABLE)
-   linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
-phydev->advertising);
-   else
-   linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
-  phydev->advertising);
+   linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
+phydev->advertising, autoneg == AUTONEG_ENABLE);
 
phydev->duplex = duplex;
 
-- 
2.11.0



[PATCH 12/14] phy: qcom-qmp: Replace devm_add_action() followed by failure action with devm_add_action_or_reset()

2019-07-08 Thread Fuqian Huang
devm_add_action_or_reset() is introduced as a helper function which 
internally calls devm_add_action(). If devm_add_action() fails 
then it will execute the action mentioned and return the error code.
This reduce source code size (avoid writing the action twice) 
and reduce the likelyhood of bugs.

Signed-off-by: Fuqian Huang 
---
 drivers/phy/qualcomm/phy-qcom-qmp.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/phy/qualcomm/phy-qcom-qmp.c 
b/drivers/phy/qualcomm/phy-qcom-qmp.c
index cd91b4179b10..677916f8968c 100644
--- a/drivers/phy/qualcomm/phy-qcom-qmp.c
+++ b/drivers/phy/qualcomm/phy-qcom-qmp.c
@@ -1837,9 +1837,7 @@ static int phy_pipe_clk_register(struct qcom_qmp *qmp, 
struct device_node *np)
 * Roll a devm action because the clock provider is the child node, but
 * the child node is not actually a device.
 */
-   ret = devm_add_action(qmp->dev, phy_pipe_clk_release_provider, np);
-   if (ret)
-   phy_pipe_clk_release_provider(np);
+   ret = devm_add_action_or_reset(qmp->dev, phy_pipe_clk_release_provider, 
np);
 
return ret;
 }
-- 
2.11.0



[PATCH 08/14] Input: elan_i2c - Replace devm_add_action() followed by failure action with devm_add_action_or_reset()

2019-07-08 Thread Fuqian Huang
devm_add_action_or_reset() is introduced as a helper function which 
internally calls devm_add_action(). If devm_add_action() fails 
then it will execute the action mentioned and return the error code.
This reduce source code size (avoid writing the action twice) 
and reduce the likelyhood of bugs.

Signed-off-by: Fuqian Huang 
---
 drivers/input/mouse/elan_i2c_core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/input/mouse/elan_i2c_core.c 
b/drivers/input/mouse/elan_i2c_core.c
index 420efaab3860..a8d4f3bd09bf 100644
--- a/drivers/input/mouse/elan_i2c_core.c
+++ b/drivers/input/mouse/elan_i2c_core.c
@@ -1234,9 +1234,8 @@ static int elan_probe(struct i2c_client *client,
return error;
}
 
-   error = devm_add_action(dev, elan_remove_sysfs_groups, data);
+   error = devm_add_action_or_reset(dev, elan_remove_sysfs_groups, data);
if (error) {
-   elan_remove_sysfs_groups(data);
dev_err(dev, "Failed to add sysfs cleanup action: %d\n",
error);
return error;
-- 
2.11.0



[PATCH 10/14] Input: auo-pixcir-ts - Replace devm_add_action() followed by failure action with devm_add_action_or_reset()

2019-07-08 Thread Fuqian Huang
devm_add_action_or_reset() is introduced as a helper function which 
internally calls devm_add_action(). If devm_add_action() fails 
then it will execute the action mentioned and return the error code.
This reduce source code size (avoid writing the action twice) 
and reduce the likelyhood of bugs.

Signed-off-by: Fuqian Huang 
---
 drivers/input/touchscreen/auo-pixcir-ts.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/input/touchscreen/auo-pixcir-ts.c 
b/drivers/input/touchscreen/auo-pixcir-ts.c
index 8e48fbda487a..8e9f3b7b8180 100644
--- a/drivers/input/touchscreen/auo-pixcir-ts.c
+++ b/drivers/input/touchscreen/auo-pixcir-ts.c
@@ -602,9 +602,8 @@ static int auo_pixcir_probe(struct i2c_client *client,
return error;
}
 
-   error = devm_add_action(>dev, auo_pixcir_reset, ts);
+   error = devm_add_action_or_reset(>dev, auo_pixcir_reset, ts);
if (error) {
-   auo_pixcir_reset(ts);
dev_err(>dev, "failed to register reset action, %d\n",
error);
return error;
-- 
2.11.0



[PATCH 13/14] thermal: rcar_gen3_thermal: Replace devm_add_action() followed by failure action with devm_add_action_or_reset()

2019-07-08 Thread Fuqian Huang
devm_add_action_or_reset() is introduced as a helper function which 
internally calls devm_add_action(). If devm_add_action() fails 
then it will execute the action mentioned and return the error code.
This reduce source code size (avoid writing the action twice) 
and reduce the likelyhood of bugs.

Signed-off-by: Fuqian Huang 
---
 drivers/thermal/rcar_gen3_thermal.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/thermal/rcar_gen3_thermal.c 
b/drivers/thermal/rcar_gen3_thermal.c
index a56463308694..755d2b5bd2c2 100644
--- a/drivers/thermal/rcar_gen3_thermal.c
+++ b/drivers/thermal/rcar_gen3_thermal.c
@@ -443,9 +443,8 @@ static int rcar_gen3_thermal_probe(struct platform_device 
*pdev)
if (ret)
goto error_unregister;
 
-   ret = devm_add_action(dev, rcar_gen3_hwmon_action, zone);
+   ret = devm_add_action_or_reset(dev, rcar_gen3_hwmon_action, 
zone);
if (ret) {
-   rcar_gen3_hwmon_action(zone);
goto error_unregister;
}
 
-- 
2.11.0



[PATCH 09/14] iio: imu: mpu6050: Replace devm_add_action() followed by failure action with devm_add_action_or_reset()

2019-07-08 Thread Fuqian Huang
devm_add_action_or_reset() is introduced as a helper function which 
internally calls devm_add_action(). If devm_add_action() fails 
then it will execute the action mentioned and return the error code.
This reduce source code size (avoid writing the action twice) 
and reduce the likelyhood of bugs.

Signed-off-by: Fuqian Huang 
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c 
b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 53a59957cc54..e067927317bd 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -1096,10 +1096,9 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, 
const char *name,
if (result)
return result;
 
-   result = devm_add_action(dev, inv_mpu_core_disable_regulator_action,
+   result = devm_add_action_or_reset(dev, 
inv_mpu_core_disable_regulator_action,
 st);
if (result) {
-   inv_mpu_core_disable_regulator_action(st);
dev_err(dev, "Failed to setup regulator cleanup action %d\n",
result);
return result;
-- 
2.11.0



[PATCH 06/14] drm/i2c: tda9950: Replace devm_add_action() followed by failure action with devm_add_action_or_reset()

2019-07-08 Thread Fuqian Huang
devm_add_action_or_reset() is introduced as a helper function which 
internally calls devm_add_action(). If devm_add_action() fails 
then it will execute the action mentioned and return the error code.
This reduce source code size (avoid writing the action twice) 
and reduce the likelyhood of bugs.

Signed-off-by: Fuqian Huang 
---
 drivers/gpu/drm/i2c/tda9950.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i2c/tda9950.c b/drivers/gpu/drm/i2c/tda9950.c
index 8039fc0d83db..042f6487e6fb 100644
--- a/drivers/gpu/drm/i2c/tda9950.c
+++ b/drivers/gpu/drm/i2c/tda9950.c
@@ -361,9 +361,7 @@ static int tda9950_devm_glue_init(struct device *dev, 
struct tda9950_glue *glue)
return ret;
}
 
-   ret = devm_add_action(dev, tda9950_devm_glue_exit, glue);
-   if (ret)
-   tda9950_devm_glue_exit(glue);
+   ret = devm_add_action_or_reset(dev, tda9950_devm_glue_exit, glue);
 
return ret;
 }
-- 
2.11.0



[PATCH 07/14] Input: cyapa - Replace devm_add_action() followed by failure action with devm_add_action_or_reset()

2019-07-08 Thread Fuqian Huang
devm_add_action_or_reset() is introduced as a helper function which 
internally calls devm_add_action(). If devm_add_action() fails 
then it will execute the action mentioned and return the error code.
This reduce source code size (avoid writing the action twice) 
and reduce the likelyhood of bugs.

Signed-off-by: Fuqian Huang 
---
 drivers/input/mouse/cyapa.c | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
index dfd3873513e4..e1d9ab558ecf 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -840,10 +840,9 @@ static int cyapa_prepare_wakeup_controls(struct cyapa 
*cyapa)
return error;
}
 
-   error = devm_add_action(dev,
+   error = devm_add_action_or_reset(dev,
cyapa_remove_power_wakeup_group, cyapa);
if (error) {
-   cyapa_remove_power_wakeup_group(cyapa);
dev_err(dev, "failed to add power cleanup action: %d\n",
error);
return error;
@@ -957,9 +956,8 @@ static int cyapa_start_runtime(struct cyapa *cyapa)
return error;
}
 
-   error = devm_add_action(dev, cyapa_remove_power_runtime_group, cyapa);
+   error = devm_add_action_or_reset(dev, cyapa_remove_power_runtime_group, 
cyapa);
if (error) {
-   cyapa_remove_power_runtime_group(cyapa);
dev_err(dev,
"failed to add power runtime cleanup action: %d\n",
error);
@@ -1298,9 +1296,8 @@ static int cyapa_probe(struct i2c_client *client,
return error;
}
 
-   error = devm_add_action(dev, cyapa_disable_regulator, cyapa);
+   error = devm_add_action_or_reset(dev, cyapa_disable_regulator, cyapa);
if (error) {
-   cyapa_disable_regulator(cyapa);
dev_err(dev, "failed to add disable regulator action: %d\n",
error);
return error;
@@ -1318,9 +1315,8 @@ static int cyapa_probe(struct i2c_client *client,
return error;
}
 
-   error = devm_add_action(dev, cyapa_remove_sysfs_group, cyapa);
+   error = devm_add_action_or_reset(dev, cyapa_remove_sysfs_group, cyapa);
if (error) {
-   cyapa_remove_sysfs_group(cyapa);
dev_err(dev, "failed to add sysfs cleanup action: %d\n", error);
return error;
}
-- 
2.11.0



[PATCH 11/14] PCI: Replace devm_add_action() followed by failure action with devm_add_action_or_reset()

2019-07-08 Thread Fuqian Huang
devm_add_action_or_reset() is introduced as a helper function which 
internally calls devm_add_action(). If devm_add_action() fails 
then it will execute the action mentioned and return the error code.
This reduce source code size (avoid writing the action twice) 
and reduce the likelyhood of bugs.

Signed-off-by: Fuqian Huang 
---
 drivers/pci/controller/pci-host-common.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/pci/controller/pci-host-common.c 
b/drivers/pci/controller/pci-host-common.c
index c742881b5061..c8cb9c5188a4 100644
--- a/drivers/pci/controller/pci-host-common.c
+++ b/drivers/pci/controller/pci-host-common.c
@@ -43,9 +43,8 @@ static struct pci_config_window *gen_pci_init(struct device 
*dev,
goto err_out;
}
 
-   err = devm_add_action(dev, gen_pci_unmap_cfg, cfg);
+   err = devm_add_action_or_reset(dev, gen_pci_unmap_cfg, cfg);
if (err) {
-   gen_pci_unmap_cfg(cfg);
goto err_out;
}
return cfg;
-- 
2.11.0



[PATCH 04/14] power: supply: sc27xx: Replace devm_add_action() followed by failure action with devm_add_action_or_reset()

2019-07-08 Thread Fuqian Huang
devm_add_action_or_reset() is introduced as a helper function which 
internally calls devm_add_action(). If devm_add_action() fails 
then it will execute the action mentioned and return the error code.
This reduce source code size (avoid writing the action twice) 
and reduce the likelyhood of bugs.

Signed-off-by: Fuqian Huang 
---
 drivers/power/supply/sc27xx_fuel_gauge.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c 
b/drivers/power/supply/sc27xx_fuel_gauge.c
index 9c184d80088b..58b2970cd359 100644
--- a/drivers/power/supply/sc27xx_fuel_gauge.c
+++ b/drivers/power/supply/sc27xx_fuel_gauge.c
@@ -1023,9 +1023,8 @@ static int sc27xx_fgu_probe(struct platform_device *pdev)
return ret;
}
 
-   ret = devm_add_action(dev, sc27xx_fgu_disable, data);
+   ret = devm_add_action_or_reset(dev, sc27xx_fgu_disable, data);
if (ret) {
-   sc27xx_fgu_disable(data);
dev_err(dev, "failed to add fgu disable action\n");
return ret;
}
-- 
2.11.0



[PATCH 05/14] drm/drv: Replace devm_add_action() followed by failure action with devm_add_action_or_reset()

2019-07-08 Thread Fuqian Huang
devm_add_action_or_reset() is introduced as a helper function which 
internally calls devm_add_action(). If devm_add_action() fails 
then it will execute the action mentioned and return the error code.
This reduce source code size (avoid writing the action twice) 
and reduce the likelyhood of bugs.

Signed-off-by: Fuqian Huang 
---
 drivers/gpu/drm/drm_drv.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 862621494a93..dd004ebbb5fd 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -760,9 +760,7 @@ int devm_drm_dev_init(struct device *parent,
if (ret)
return ret;
 
-   ret = devm_add_action(parent, devm_drm_dev_init_release, dev);
-   if (ret)
-   devm_drm_dev_init_release(dev);
+   ret = devm_add_action_or_reset(parent, devm_drm_dev_init_release, dev);
 
return ret;
 }
-- 
2.11.0



[PATCH 02/14] iio: adc: sc27xx: Replace devm_add_action() followed by failure action with devm_add_action_or_reset()

2019-07-08 Thread Fuqian Huang
devm_add_action_or_reset() is introduced as a helper function which 
internally calls devm_add_action(). If devm_add_action() fails 
then it will execute the action mentioned and return the error code.
This reduce source code size (avoid writing the action twice) 
and reduce the likelyhood of bugs.

Signed-off-by: Fuqian Huang 
---
 drivers/iio/adc/sc27xx_adc.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/adc/sc27xx_adc.c b/drivers/iio/adc/sc27xx_adc.c
index ec86f640e963..d7ca002cbb17 100644
--- a/drivers/iio/adc/sc27xx_adc.c
+++ b/drivers/iio/adc/sc27xx_adc.c
@@ -546,10 +546,9 @@ static int sc27xx_adc_probe(struct platform_device *pdev)
return -ENXIO;
}
 
-   ret = devm_add_action(dev, sc27xx_adc_free_hwlock,
+   ret = devm_add_action_or_reset(dev, sc27xx_adc_free_hwlock,
  sc27xx_data->hwlock);
if (ret) {
-   sc27xx_adc_free_hwlock(sc27xx_data->hwlock);
dev_err(dev, "failed to add hwspinlock action\n");
return ret;
}
@@ -563,9 +562,8 @@ static int sc27xx_adc_probe(struct platform_device *pdev)
return ret;
}
 
-   ret = devm_add_action(dev, sc27xx_adc_disable, sc27xx_data);
+   ret = devm_add_action_or_reset(dev, sc27xx_adc_disable, sc27xx_data);
if (ret) {
-   sc27xx_adc_disable(sc27xx_data);
dev_err(dev, "failed to add ADC disable action\n");
return ret;
}
-- 
2.11.0



[PATCH 03/14] power: supply: sc27xx: Introduce local variable 'struct device *dev'

2019-07-08 Thread Fuqian Huang
Introduce local variable 'struct device *dev' and use it instead of
dereferencing it repeatly.

Signed-off-by: Fuqian Huang 
---
 drivers/power/supply/sc27xx_fuel_gauge.c | 47 
 1 file changed, 24 insertions(+), 23 deletions(-)

diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c 
b/drivers/power/supply/sc27xx_fuel_gauge.c
index 24895cc3b41e..9c184d80088b 100644
--- a/drivers/power/supply/sc27xx_fuel_gauge.c
+++ b/drivers/power/supply/sc27xx_fuel_gauge.c
@@ -957,81 +957,82 @@ static int sc27xx_fgu_hw_init(struct sc27xx_fgu_data 
*data)
 
 static int sc27xx_fgu_probe(struct platform_device *pdev)
 {
-   struct device_node *np = pdev->dev.of_node;
+   struct device *dev = >dev;
+   struct device_node *np = dev->of_node;
struct power_supply_config fgu_cfg = { };
struct sc27xx_fgu_data *data;
int ret, irq;
 
-   data = devm_kzalloc(>dev, sizeof(*data), GFP_KERNEL);
+   data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
 
-   data->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+   data->regmap = dev_get_regmap(dev->parent, NULL);
if (!data->regmap) {
-   dev_err(>dev, "failed to get regmap\n");
+   dev_err(dev, "failed to get regmap\n");
return -ENODEV;
}
 
-   ret = device_property_read_u32(>dev, "reg", >base);
+   ret = device_property_read_u32(dev, "reg", >base);
if (ret) {
-   dev_err(>dev, "failed to get fgu address\n");
+   dev_err(dev, "failed to get fgu address\n");
return ret;
}
 
-   data->channel = devm_iio_channel_get(>dev, "bat-temp");
+   data->channel = devm_iio_channel_get(dev, "bat-temp");
if (IS_ERR(data->channel)) {
-   dev_err(>dev, "failed to get IIO channel\n");
+   dev_err(dev, "failed to get IIO channel\n");
return PTR_ERR(data->channel);
}
 
-   data->charge_chan = devm_iio_channel_get(>dev, "charge-vol");
+   data->charge_chan = devm_iio_channel_get(dev, "charge-vol");
if (IS_ERR(data->charge_chan)) {
-   dev_err(>dev, "failed to get charge IIO channel\n");
+   dev_err(dev, "failed to get charge IIO channel\n");
return PTR_ERR(data->charge_chan);
}
 
-   data->gpiod = devm_gpiod_get(>dev, "bat-detect", GPIOD_IN);
+   data->gpiod = devm_gpiod_get(dev, "bat-detect", GPIOD_IN);
if (IS_ERR(data->gpiod)) {
-   dev_err(>dev, "failed to get battery detection GPIO\n");
+   dev_err(dev, "failed to get battery detection GPIO\n");
return PTR_ERR(data->gpiod);
}
 
ret = gpiod_get_value_cansleep(data->gpiod);
if (ret < 0) {
-   dev_err(>dev, "failed to get gpio state\n");
+   dev_err(dev, "failed to get gpio state\n");
return ret;
}
 
data->bat_present = !!ret;
mutex_init(>lock);
-   data->dev = >dev;
+   data->dev = dev;
platform_set_drvdata(pdev, data);
 
fgu_cfg.drv_data = data;
fgu_cfg.of_node = np;
-   data->battery = devm_power_supply_register(>dev, _fgu_desc,
+   data->battery = devm_power_supply_register(dev, _fgu_desc,
   _cfg);
if (IS_ERR(data->battery)) {
-   dev_err(>dev, "failed to register power supply\n");
+   dev_err(dev, "failed to register power supply\n");
return PTR_ERR(data->battery);
}
 
ret = sc27xx_fgu_hw_init(data);
if (ret) {
-   dev_err(>dev, "failed to initialize fgu hardware\n");
+   dev_err(dev, "failed to initialize fgu hardware\n");
return ret;
}
 
-   ret = devm_add_action(>dev, sc27xx_fgu_disable, data);
+   ret = devm_add_action(dev, sc27xx_fgu_disable, data);
if (ret) {
sc27xx_fgu_disable(data);
-   dev_err(>dev, "failed to add fgu disable action\n");
+   dev_err(dev, "failed to add fgu disable action\n");
return ret;
}
 
irq = platform_get_irq(pdev, 0);
if (irq < 0) {
-   dev_err(>dev, "no irq resource specified\n");
+   dev_err(dev, "no irq resource specified\n");
return irq;
}
 
@@ -1046,17 +1047,17 @@ static int sc27xx_fgu_probe(struct platform_

[PATCH 01/14] iio: adc: sc27xx: Introduce local variable 'struct device *dev'

2019-07-08 Thread Fuqian Huang
Introduce local variable 'struct device *dev' and use it instead of
dereferencing it repeatly.

Signed-off-by: Fuqian Huang 
---
 drivers/iio/adc/sc27xx_adc.c | 41 +
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/drivers/iio/adc/sc27xx_adc.c b/drivers/iio/adc/sc27xx_adc.c
index f7f7a18904b4..ec86f640e963 100644
--- a/drivers/iio/adc/sc27xx_adc.c
+++ b/drivers/iio/adc/sc27xx_adc.c
@@ -504,88 +504,89 @@ static void sc27xx_adc_free_hwlock(void *_data)
 
 static int sc27xx_adc_probe(struct platform_device *pdev)
 {
-   struct device_node *np = pdev->dev.of_node;
+   struct device *dev = >dev;
+   struct device_node *np = dev->of_node;
struct sc27xx_adc_data *sc27xx_data;
struct iio_dev *indio_dev;
int ret;
 
-   indio_dev = devm_iio_device_alloc(>dev, sizeof(*sc27xx_data));
+   indio_dev = devm_iio_device_alloc(dev, sizeof(*sc27xx_data));
if (!indio_dev)
return -ENOMEM;
 
sc27xx_data = iio_priv(indio_dev);
 
-   sc27xx_data->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+   sc27xx_data->regmap = dev_get_regmap(dev->parent, NULL);
if (!sc27xx_data->regmap) {
-   dev_err(>dev, "failed to get ADC regmap\n");
+   dev_err(dev, "failed to get ADC regmap\n");
return -ENODEV;
}
 
ret = of_property_read_u32(np, "reg", _data->base);
if (ret) {
-   dev_err(>dev, "failed to get ADC base address\n");
+   dev_err(dev, "failed to get ADC base address\n");
return ret;
}
 
sc27xx_data->irq = platform_get_irq(pdev, 0);
if (sc27xx_data->irq < 0) {
-   dev_err(>dev, "failed to get ADC irq number\n");
+   dev_err(dev, "failed to get ADC irq number\n");
return sc27xx_data->irq;
}
 
ret = of_hwspin_lock_get_id(np, 0);
if (ret < 0) {
-   dev_err(>dev, "failed to get hwspinlock id\n");
+   dev_err(dev, "failed to get hwspinlock id\n");
return ret;
}
 
sc27xx_data->hwlock = hwspin_lock_request_specific(ret);
if (!sc27xx_data->hwlock) {
-   dev_err(>dev, "failed to request hwspinlock\n");
+   dev_err(dev, "failed to request hwspinlock\n");
return -ENXIO;
}
 
-   ret = devm_add_action(>dev, sc27xx_adc_free_hwlock,
+   ret = devm_add_action(dev, sc27xx_adc_free_hwlock,
  sc27xx_data->hwlock);
if (ret) {
sc27xx_adc_free_hwlock(sc27xx_data->hwlock);
-   dev_err(>dev, "failed to add hwspinlock action\n");
+   dev_err(dev, "failed to add hwspinlock action\n");
return ret;
}
 
init_completion(_data->completion);
-   sc27xx_data->dev = >dev;
+   sc27xx_data->dev = dev;
 
ret = sc27xx_adc_enable(sc27xx_data);
if (ret) {
-   dev_err(>dev, "failed to enable ADC module\n");
+   dev_err(dev, "failed to enable ADC module\n");
return ret;
}
 
-   ret = devm_add_action(>dev, sc27xx_adc_disable, sc27xx_data);
+   ret = devm_add_action(dev, sc27xx_adc_disable, sc27xx_data);
if (ret) {
sc27xx_adc_disable(sc27xx_data);
-   dev_err(>dev, "failed to add ADC disable action\n");
+   dev_err(dev, "failed to add ADC disable action\n");
return ret;
}
 
-   ret = devm_request_threaded_irq(>dev, sc27xx_data->irq, NULL,
+   ret = devm_request_threaded_irq(dev, sc27xx_data->irq, NULL,
sc27xx_adc_isr, IRQF_ONESHOT,
pdev->name, sc27xx_data);
if (ret) {
-   dev_err(>dev, "failed to request ADC irq\n");
+   dev_err(dev, "failed to request ADC irq\n");
return ret;
}
 
-   indio_dev->dev.parent = >dev;
-   indio_dev->name = dev_name(>dev);
+   indio_dev->dev.parent = dev;
+   indio_dev->name = dev_name(dev);
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->info = _info;
indio_dev->channels = sc27xx_channels;
indio_dev->num_channels = ARRAY_SIZE(sc27xx_channels);
-   ret = devm_iio_device_register(>dev, indio_dev);
+   ret = devm_iio_device_register(dev, indio_dev);
if (ret)
-   dev_err(>dev, "could not register iio (ADC)");
+   dev_err(dev, "could not register iio (ADC)");
 
return ret;
 }
-- 
2.11.0



[Patch v2 10/10] platform/x86/asus-wmi: using dev_get_drvdata directly

2019-07-03 Thread Fuqian Huang
Several drivers cast a struct device pointer to a struct
platform_device pointer only to then call platform_get_drvdata().
To improve readability, these constructs can be simplified
by using dev_get_drvdata() directly.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Make the commit message more clearly.

 drivers/platform/x86/asus-wmi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index 9b18a184e0aa..49049b02a015 100644
--- a/drivers/platform/x86/asus-wmi.c
+++ b/drivers/platform/x86/asus-wmi.c
@@ -1353,8 +1353,7 @@ static umode_t asus_hwmon_sysfs_is_visible(struct kobject 
*kobj,
  struct attribute *attr, int idx)
 {
struct device *dev = container_of(kobj, struct device, kobj);
-   struct platform_device *pdev = to_platform_device(dev->parent);
-   struct asus_wmi *asus = platform_get_drvdata(pdev);
+   struct asus_wmi *asus = dev_get_drvdata(dev->parent);
int dev_id = -1;
int fan_attr = -1;
u32 value = ASUS_WMI_UNSUPPORTED_METHOD;
-- 
2.11.0



[Patch v2 09/10] net/ethernet: using dev_get_drvdata directly

2019-07-03 Thread Fuqian Huang
Several drivers cast a struct device pointer to a struct
platform_device pointer only to then call platform_get_drvdata().
To improve readability, these constructs can be simplified
by using dev_get_drvdata() directly.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Make the commit message more clearly.

 drivers/net/ethernet/calxeda/xgmac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/calxeda/xgmac.c 
b/drivers/net/ethernet/calxeda/xgmac.c
index 11d4e91ea754..99f49d059414 100644
--- a/drivers/net/ethernet/calxeda/xgmac.c
+++ b/drivers/net/ethernet/calxeda/xgmac.c
@@ -1855,7 +1855,7 @@ static void xgmac_pmt(void __iomem *ioaddr, unsigned long 
mode)
 
 static int xgmac_suspend(struct device *dev)
 {
-   struct net_device *ndev = platform_get_drvdata(to_platform_device(dev));
+   struct net_device *ndev = dev_get_drvdata(dev);
struct xgmac_priv *priv = netdev_priv(ndev);
u32 value;
 
@@ -1881,7 +1881,7 @@ static int xgmac_suspend(struct device *dev)
 
 static int xgmac_resume(struct device *dev)
 {
-   struct net_device *ndev = platform_get_drvdata(to_platform_device(dev));
+   struct net_device *ndev = dev_get_drvdata(dev);
struct xgmac_priv *priv = netdev_priv(ndev);
void __iomem *ioaddr = priv->base;
 
-- 
2.11.0



[Patch v2 08/10] net/can: using dev_get_drvdata directly

2019-07-03 Thread Fuqian Huang
Several drivers cast a struct device pointer to a struct
platform_device pointer only to then call platform_get_drvdata().
To improve readability, these constructs can be simplified
by using dev_get_drvdata() directly.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Make the commit message more clearly.

 drivers/net/can/softing/softing_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/softing/softing_main.c 
b/drivers/net/can/softing/softing_main.c
index 68bb58a57f3b..8242fb287cbb 100644
--- a/drivers/net/can/softing/softing_main.c
+++ b/drivers/net/can/softing/softing_main.c
@@ -683,7 +683,7 @@ static void softing_netdev_cleanup(struct net_device 
*netdev)
 static ssize_t show_##name(struct device *dev, \
struct device_attribute *attr, char *buf) \
 { \
-   struct softing *card = platform_get_drvdata(to_platform_device(dev)); \
+   struct softing *card = dev_get_drvdata(dev); \
return sprintf(buf, "%u\n", card->member); \
 } \
 static DEVICE_ATTR(name, 0444, show_##name, NULL)
@@ -692,7 +692,7 @@ static DEVICE_ATTR(name, 0444, show_##name, NULL)
 static ssize_t show_##name(struct device *dev, \
struct device_attribute *attr, char *buf) \
 { \
-   struct softing *card = platform_get_drvdata(to_platform_device(dev)); \
+   struct softing *card = dev_get_drvdata(dev); \
return sprintf(buf, "%s\n", card->member); \
 } \
 static DEVICE_ATTR(name, 0444, show_##name, NULL)
-- 
2.11.0



[Patch v2 05/10] iio: using dev_get_drvdata directly

2019-07-03 Thread Fuqian Huang
Several drivers cast a struct device pointer to a struct
platform_device pointer only to then call platform_get_drvdata().
To improve readability, these constructs can be simplified
by using dev_get_drvdata() directly.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Make the commit message more clearly.

 drivers/iio/adc/at91-sama5d2_adc.c | 12 
 drivers/iio/adc/at91_adc.c |  4 ++--
 2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/iio/adc/at91-sama5d2_adc.c 
b/drivers/iio/adc/at91-sama5d2_adc.c
index d384cf0250ff..a2837a0e7cba 100644
--- a/drivers/iio/adc/at91-sama5d2_adc.c
+++ b/drivers/iio/adc/at91-sama5d2_adc.c
@@ -1578,8 +1578,7 @@ static void at91_adc_hw_init(struct at91_adc_state *st)
 static ssize_t at91_adc_get_fifo_state(struct device *dev,
   struct device_attribute *attr, char *buf)
 {
-   struct iio_dev *indio_dev =
-   platform_get_drvdata(to_platform_device(dev));
+   struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct at91_adc_state *st = iio_priv(indio_dev);
 
return scnprintf(buf, PAGE_SIZE, "%d\n", !!st->dma_st.dma_chan);
@@ -1588,8 +1587,7 @@ static ssize_t at91_adc_get_fifo_state(struct device *dev,
 static ssize_t at91_adc_get_watermark(struct device *dev,
  struct device_attribute *attr, char *buf)
 {
-   struct iio_dev *indio_dev =
-   platform_get_drvdata(to_platform_device(dev));
+   struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct at91_adc_state *st = iio_priv(indio_dev);
 
return scnprintf(buf, PAGE_SIZE, "%d\n", st->dma_st.watermark);
@@ -1841,8 +1839,7 @@ static int at91_adc_remove(struct platform_device *pdev)
 
 static __maybe_unused int at91_adc_suspend(struct device *dev)
 {
-   struct iio_dev *indio_dev =
-   platform_get_drvdata(to_platform_device(dev));
+   struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct at91_adc_state *st = iio_priv(indio_dev);
 
/*
@@ -1862,8 +1859,7 @@ static __maybe_unused int at91_adc_suspend(struct device 
*dev)
 
 static __maybe_unused int at91_adc_resume(struct device *dev)
 {
-   struct iio_dev *indio_dev =
-   platform_get_drvdata(to_platform_device(dev));
+   struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct at91_adc_state *st = iio_priv(indio_dev);
int ret;
 
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index d23709ed9049..32f1c4a33b20 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -1359,7 +1359,7 @@ static int at91_adc_remove(struct platform_device *pdev)
 #ifdef CONFIG_PM_SLEEP
 static int at91_adc_suspend(struct device *dev)
 {
-   struct iio_dev *idev = platform_get_drvdata(to_platform_device(dev));
+   struct iio_dev *idev = dev_get_drvdata(dev);
struct at91_adc_state *st = iio_priv(idev);
 
pinctrl_pm_select_sleep_state(dev);
@@ -1370,7 +1370,7 @@ static int at91_adc_suspend(struct device *dev)
 
 static int at91_adc_resume(struct device *dev)
 {
-   struct iio_dev *idev = platform_get_drvdata(to_platform_device(dev));
+   struct iio_dev *idev = dev_get_drvdata(dev);
struct at91_adc_state *st = iio_priv(idev);
 
clk_prepare_enable(st->clk);
-- 
2.11.0



[Patch v2 07/10] mailbox: using dev_get_drvdata directly

2019-07-03 Thread Fuqian Huang
Several drivers cast a struct device pointer to a struct
platform_device pointer only to then call platform_get_drvdata().
To improve readability, these constructs can be simplified
by using dev_get_drvdata() directly.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Make the commit message more clearly.

 drivers/mailbox/bcm-flexrm-mailbox.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/mailbox/bcm-flexrm-mailbox.c 
b/drivers/mailbox/bcm-flexrm-mailbox.c
index a64116586b4c..0cfdd53d04a1 100644
--- a/drivers/mailbox/bcm-flexrm-mailbox.c
+++ b/drivers/mailbox/bcm-flexrm-mailbox.c
@@ -1165,8 +1165,7 @@ static int flexrm_process_completions(struct flexrm_ring 
*ring)
 
 static int flexrm_debugfs_conf_show(struct seq_file *file, void *offset)
 {
-   struct platform_device *pdev = to_platform_device(file->private);
-   struct flexrm_mbox *mbox = platform_get_drvdata(pdev);
+   struct flexrm_mbox *mbox = dev_get_drvdata(file->private);
 
/* Write config in file */
flexrm_write_config_in_seqfile(mbox, file);
@@ -1176,8 +1175,7 @@ static int flexrm_debugfs_conf_show(struct seq_file 
*file, void *offset)
 
 static int flexrm_debugfs_stats_show(struct seq_file *file, void *offset)
 {
-   struct platform_device *pdev = to_platform_device(file->private);
-   struct flexrm_mbox *mbox = platform_get_drvdata(pdev);
+   struct flexrm_mbox *mbox = dev_get_drvdata(file->private);
 
/* Write stats in file */
flexrm_write_stats_in_seqfile(mbox, file);
-- 
2.11.0



[Patch v2 04/10] drm/panfrost: using dev_get_drvdata directly

2019-07-03 Thread Fuqian Huang
Several drivers cast a struct device pointer to a struct
platform_device pointer only to then call platform_get_drvdata().
To improve readability, these constructs can be simplified
by using dev_get_drvdata() directly.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Make the commit message more clearly.

 drivers/gpu/drm/panfrost/panfrost_devfreq.c | 6 +++---
 drivers/gpu/drm/panfrost/panfrost_device.c  | 6 ++
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/panfrost/panfrost_devfreq.c 
b/drivers/gpu/drm/panfrost/panfrost_devfreq.c
index db798532b0b6..bef5df4d99ac 100644
--- a/drivers/gpu/drm/panfrost/panfrost_devfreq.c
+++ b/drivers/gpu/drm/panfrost/panfrost_devfreq.c
@@ -18,7 +18,7 @@ static void panfrost_devfreq_update_utilization(struct 
panfrost_device *pfdev, i
 static int panfrost_devfreq_target(struct device *dev, unsigned long *freq,
   u32 flags)
 {
-   struct panfrost_device *pfdev = 
platform_get_drvdata(to_platform_device(dev));
+   struct panfrost_device *pfdev = dev_get_drvdata(dev);
struct dev_pm_opp *opp;
unsigned long old_clk_rate = pfdev->devfreq.cur_freq;
unsigned long target_volt, target_rate;
@@ -86,7 +86,7 @@ static void panfrost_devfreq_reset(struct panfrost_device 
*pfdev)
 static int panfrost_devfreq_get_dev_status(struct device *dev,
   struct devfreq_dev_status *status)
 {
-   struct panfrost_device *pfdev = 
platform_get_drvdata(to_platform_device(dev));
+   struct panfrost_device *pfdev = dev_get_drvdata(dev);
int i;
 
for (i = 0; i < NUM_JOB_SLOTS; i++) {
@@ -117,7 +117,7 @@ static int panfrost_devfreq_get_dev_status(struct device 
*dev,
 
 static int panfrost_devfreq_get_cur_freq(struct device *dev, unsigned long 
*freq)
 {
-   struct panfrost_device *pfdev = 
platform_get_drvdata(to_platform_device(dev));
+   struct panfrost_device *pfdev = dev_get_drvdata(dev);
 
*freq = pfdev->devfreq.cur_freq;
 
diff --git a/drivers/gpu/drm/panfrost/panfrost_device.c 
b/drivers/gpu/drm/panfrost/panfrost_device.c
index 3b2bced1b015..ed187648e6d8 100644
--- a/drivers/gpu/drm/panfrost/panfrost_device.c
+++ b/drivers/gpu/drm/panfrost/panfrost_device.c
@@ -227,8 +227,7 @@ const char *panfrost_exception_name(struct panfrost_device 
*pfdev, u32 exception
 #ifdef CONFIG_PM
 int panfrost_device_resume(struct device *dev)
 {
-   struct platform_device *pdev = to_platform_device(dev);
-   struct panfrost_device *pfdev = platform_get_drvdata(pdev);
+   struct panfrost_device *pfdev = dev_get_drvdata(dev);
 
panfrost_gpu_soft_reset(pfdev);
 
@@ -243,8 +242,7 @@ int panfrost_device_resume(struct device *dev)
 
 int panfrost_device_suspend(struct device *dev)
 {
-   struct platform_device *pdev = to_platform_device(dev);
-   struct panfrost_device *pfdev = platform_get_drvdata(pdev);
+   struct panfrost_device *pfdev = dev_get_drvdata(dev);
 
if (!panfrost_job_is_idle(pfdev))
return -EBUSY;
-- 
2.11.0



[Patch v2 03/10] drm/omapdrm: using dev_get_drvdata directly

2019-07-03 Thread Fuqian Huang
Several drivers cast a struct device pointer to a struct
platform_device pointer only to then call platform_get_drvdata().
To improve readability, these constructs can be simplified
by using dev_get_drvdata() directly.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Make the commit message more clearly.

 drivers/gpu/drm/omapdrm/displays/panel-dsi-cm.c | 15 +--
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/displays/panel-dsi-cm.c 
b/drivers/gpu/drm/omapdrm/displays/panel-dsi-cm.c
index 8edef8ef23b0..53240da139b1 100644
--- a/drivers/gpu/drm/omapdrm/displays/panel-dsi-cm.c
+++ b/drivers/gpu/drm/omapdrm/displays/panel-dsi-cm.c
@@ -407,8 +407,7 @@ static const struct backlight_ops dsicm_bl_ops = {
 static ssize_t dsicm_num_errors_show(struct device *dev,
struct device_attribute *attr, char *buf)
 {
-   struct platform_device *pdev = to_platform_device(dev);
-   struct panel_drv_data *ddata = platform_get_drvdata(pdev);
+   struct panel_drv_data *ddata = dev_get_drvdata(dev);
struct omap_dss_device *src = ddata->src;
u8 errors = 0;
int r;
@@ -439,8 +438,7 @@ static ssize_t dsicm_num_errors_show(struct device *dev,
 static ssize_t dsicm_hw_revision_show(struct device *dev,
struct device_attribute *attr, char *buf)
 {
-   struct platform_device *pdev = to_platform_device(dev);
-   struct panel_drv_data *ddata = platform_get_drvdata(pdev);
+   struct panel_drv_data *ddata = dev_get_drvdata(dev);
struct omap_dss_device *src = ddata->src;
u8 id1, id2, id3;
int r;
@@ -506,8 +504,7 @@ static ssize_t dsicm_show_ulps(struct device *dev,
struct device_attribute *attr,
char *buf)
 {
-   struct platform_device *pdev = to_platform_device(dev);
-   struct panel_drv_data *ddata = platform_get_drvdata(pdev);
+   struct panel_drv_data *ddata = dev_get_drvdata(dev);
unsigned int t;
 
mutex_lock(>lock);
@@ -521,8 +518,7 @@ static ssize_t dsicm_store_ulps_timeout(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
 {
-   struct platform_device *pdev = to_platform_device(dev);
-   struct panel_drv_data *ddata = platform_get_drvdata(pdev);
+   struct panel_drv_data *ddata = dev_get_drvdata(dev);
struct omap_dss_device *src = ddata->src;
unsigned long t;
int r;
@@ -553,8 +549,7 @@ static ssize_t dsicm_show_ulps_timeout(struct device *dev,
struct device_attribute *attr,
char *buf)
 {
-   struct platform_device *pdev = to_platform_device(dev);
-   struct panel_drv_data *ddata = platform_get_drvdata(pdev);
+   struct panel_drv_data *ddata = dev_get_drvdata(dev);
unsigned int t;
 
mutex_lock(>lock);
-- 
2.11.0



[PATCH v2 35/35] sound/soc/intel: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)
  - Split into two patches

 sound/soc/intel/atom/sst/sst_loader.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/sound/soc/intel/atom/sst/sst_loader.c 
b/sound/soc/intel/atom/sst/sst_loader.c
index ce11c36848c4..cc95af35c060 100644
--- a/sound/soc/intel/atom/sst/sst_loader.c
+++ b/sound/soc/intel/atom/sst/sst_loader.c
@@ -288,14 +288,13 @@ static int sst_cache_and_parse_fw(struct intel_sst_drv 
*sst,
 {
int retval = 0;
 
-   sst->fw_in_mem = kzalloc(fw->size, GFP_KERNEL);
+   sst->fw_in_mem = kmemdup(fw->data, fw->size, GFP_KERNEL);
if (!sst->fw_in_mem) {
retval = -ENOMEM;
goto end_release;
}
dev_dbg(sst->dev, "copied fw to %p", sst->fw_in_mem);
dev_dbg(sst->dev, "phys: %lx", (unsigned 
long)virt_to_phys(sst->fw_in_mem));
-   memcpy(sst->fw_in_mem, fw->data, fw->size);
retval = sst_parse_fw_memcpy(sst, fw->size, >memcpy_list);
if (retval) {
dev_err(sst->dev, "Failed to parse fw\n");
-- 
2.11.0



[PATCH v2 34/35] sound/soc/codecs: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Acked-by: Richard Fitzgerald 
Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)
  - Split into two patches

 sound/soc/codecs/wm0010.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/sound/soc/codecs/wm0010.c b/sound/soc/codecs/wm0010.c
index 727d6703c905..807826f30f58 100644
--- a/sound/soc/codecs/wm0010.c
+++ b/sound/soc/codecs/wm0010.c
@@ -515,7 +515,7 @@ static int wm0010_stage2_load(struct snd_soc_component 
*component)
dev_dbg(component->dev, "Downloading %zu byte stage 2 loader\n", 
fw->size);
 
/* Copy to local buffer first as vmalloc causes problems for dma */
-   img = kzalloc(fw->size, GFP_KERNEL | GFP_DMA);
+   img = kmemdup(>data[0], fw->size, GFP_KERNEL | GFP_DMA);
if (!img) {
ret = -ENOMEM;
goto abort2;
@@ -527,8 +527,6 @@ static int wm0010_stage2_load(struct snd_soc_component 
*component)
goto abort1;
}
 
-   memcpy(img, >data[0], fw->size);
-
spi_message_init();
memset(, 0, sizeof(t));
t.rx_buf = out;
-- 
2.11.0



[PATCH v2 32/35] omfs: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 fs/omfs/inode.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/omfs/inode.c b/fs/omfs/inode.c
index 08226a835ec3..1aa0c0a224b1 100644
--- a/fs/omfs/inode.c
+++ b/fs/omfs/inode.c
@@ -363,12 +363,11 @@ static int omfs_get_imap(struct super_block *sb)
bh = sb_bread(sb, block++);
if (!bh)
goto nomem_free;
-   *ptr = kmalloc(sb->s_blocksize, GFP_KERNEL);
+   *ptr = kmemdup(bh->b_data, sb->s_blocksize, GFP_KERNEL);
if (!*ptr) {
brelse(bh);
goto nomem_free;
}
-   memcpy(*ptr, bh->b_data, sb->s_blocksize);
if (count < sb->s_blocksize)
memset((void *)*ptr + count, 0xff,
sb->s_blocksize - count);
-- 
2.11.0



[PATCH v2 33/35] sound/pci: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 sound/pci/echoaudio/echoaudio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
index b612a536a5a1..35bd3e7c8ce1 100644
--- a/sound/pci/echoaudio/echoaudio.c
+++ b/sound/pci/echoaudio/echoaudio.c
@@ -2189,11 +2189,10 @@ static int snd_echo_resume(struct device *dev)
u32 pipe_alloc_mask;
int err;
 
-   commpage_bak = kmalloc(sizeof(*commpage), GFP_KERNEL);
+   commpage_bak = kmemdup(commpage, sizeof(*commpage), GFP_KERNEL);
if (commpage_bak == NULL)
return -ENOMEM;
commpage = chip->comm_page;
-   memcpy(commpage_bak, commpage, sizeof(*commpage));
 
err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device);
if (err < 0) {
-- 
2.11.0



[PATCH v2 31/35] ocfs2: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 fs/ocfs2/alloc.c  | 8 +++-
 fs/ocfs2/localalloc.c | 6 ++
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index d1348fc4ca6d..d4911d70c326 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -6191,17 +6191,15 @@ int ocfs2_begin_truncate_log_recovery(struct 
ocfs2_super *osb,
if (le16_to_cpu(tl->tl_used)) {
trace_ocfs2_truncate_log_recovery_num(le16_to_cpu(tl->tl_used));
 
-   *tl_copy = kmalloc(tl_bh->b_size, GFP_KERNEL);
+   /* Assuming the write-out below goes well, this copy
+* will be passed back to recovery for processing. */
+   *tl_copy = kmemdup(tl_bh->b_data, tl_bh->b_size, GFP_KERNEL);
if (!(*tl_copy)) {
status = -ENOMEM;
mlog_errno(status);
goto bail;
}
 
-   /* Assuming the write-out below goes well, this copy
-* will be passed back to recovery for processing. */
-   memcpy(*tl_copy, tl_bh->b_data, tl_bh->b_size);
-
/* All we need to do to clear the truncate log is set
 * tl_used. */
tl->tl_used = 0;
diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
index f03674afbd30..158e5af767fd 100644
--- a/fs/ocfs2/localalloc.c
+++ b/fs/ocfs2/localalloc.c
@@ -424,12 +424,11 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb)
bh = osb->local_alloc_bh;
alloc = (struct ocfs2_dinode *) bh->b_data;
 
-   alloc_copy = kmalloc(bh->b_size, GFP_NOFS);
+   alloc_copy = kmemdup(alloc, bh->b_size, GFP_NOFS);
if (!alloc_copy) {
status = -ENOMEM;
goto out_commit;
}
-   memcpy(alloc_copy, alloc, bh->b_size);
 
status = ocfs2_journal_access_di(handle, INODE_CACHE(local_alloc_inode),
 bh, OCFS2_JOURNAL_ACCESS_WRITE);
@@ -1272,13 +1271,12 @@ static int ocfs2_local_alloc_slide_window(struct 
ocfs2_super *osb,
 * local alloc shutdown won't try to double free main bitmap
 * bits. Make a copy so the sync function knows which bits to
 * free. */
-   alloc_copy = kmalloc(osb->local_alloc_bh->b_size, GFP_NOFS);
+   alloc_copy = kmemdup(alloc, osb->local_alloc_bh->b_size, GFP_NOFS);
if (!alloc_copy) {
status = -ENOMEM;
mlog_errno(status);
goto bail;
}
-   memcpy(alloc_copy, alloc, osb->local_alloc_bh->b_size);
 
status = ocfs2_journal_access_di(handle,
 INODE_CACHE(local_alloc_inode),
-- 
2.11.0



[PATCH v2 29/35] nfsd: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 fs/nfsd/nfscache.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
index da52b594362a..c0226f0281af 100644
--- a/fs/nfsd/nfscache.c
+++ b/fs/nfsd/nfscache.c
@@ -533,13 +533,12 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, 
__be32 *statp)
case RC_REPLBUFF:
cachv = >c_replvec;
bufsize = len << 2;
-   cachv->iov_base = kmalloc(bufsize, GFP_KERNEL);
+   cachv->iov_base = kmemdup(statp, bufsize, GFP_KERNEL);
if (!cachv->iov_base) {
nfsd_reply_cache_free(b, rp);
return;
}
cachv->iov_len = bufsize;
-   memcpy(cachv->iov_base, statp, bufsize);
break;
case RC_NOCACHE:
nfsd_reply_cache_free(b, rp);
-- 
2.11.0



[PATCH v2 28/35] ext4: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 fs/ext4/xattr.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 491f9ee4040e..d09040df7014 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -1898,11 +1898,10 @@ ext4_xattr_block_set(handle_t *handle, struct inode 
*inode,
 
unlock_buffer(bs->bh);
ea_bdebug(bs->bh, "cloning");
-   s->base = kmalloc(bs->bh->b_size, GFP_NOFS);
+   s->base = kmemdup(BHDR(bs->bh), bs->bh->b_size, 
GFP_NOFS);
error = -ENOMEM;
if (s->base == NULL)
goto cleanup;
-   memcpy(s->base, BHDR(bs->bh), bs->bh->b_size);
s->first = ENTRY(header(s->base)+1);
header(s->base)->h_refcount = cpu_to_le32(1);
s->here = ENTRY(s->base + offset);
-- 
2.11.0



[PATCH v2 30/35] ntfs: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 fs/ntfs/dir.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
index 3c4811469ae8..eed63f045bd5 100644
--- a/fs/ntfs/dir.c
+++ b/fs/ntfs/dir.c
@@ -1158,14 +1158,14 @@ static int ntfs_readdir(struct file *file, struct 
dir_context *actor)
 * map the mft record without deadlocking.
 */
rc = le32_to_cpu(ctx->attr->data.resident.value_length);
-   ir = kmalloc(rc, GFP_NOFS);
+   /* Copy the index root value (it has been verified in read_inode). */
+   ir = kmemdup((u8 *)ctx->attr +
+   le16_to_cpu(ctx->attr->data.resident.value_offset), rc, 
GFP_NOFS);
if (unlikely(!ir)) {
err = -ENOMEM;
goto err_out;
}
-   /* Copy the index root value (it has been verified in read_inode). */
-   memcpy(ir, (u8*)ctx->attr +
-   le16_to_cpu(ctx->attr->data.resident.value_offset), rc);
+
ntfs_attr_put_search_ctx(ctx);
unmap_mft_record(ndir);
ctx = NULL;
-- 
2.11.0



[PATCH v2 27/35] ext2: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 fs/ext2/xattr.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
index 1e33e0ac8cf1..a9c641cd5484 100644
--- a/fs/ext2/xattr.c
+++ b/fs/ext2/xattr.c
@@ -506,11 +506,10 @@ bad_block:ext2_error(sb, "ext2_xattr_set",
 
unlock_buffer(bh);
ea_bdebug(bh, "cloning");
-   header = kmalloc(bh->b_size, GFP_KERNEL);
+   header = kmemdup(HDR(bh), bh->b_size, GFP_KERNEL);
error = -ENOMEM;
if (header == NULL)
goto cleanup;
-   memcpy(header, HDR(bh), bh->b_size);
header->h_refcount = cpu_to_le32(1);
 
offset = (char *)here - bh->b_data;
-- 
2.11.0



[PATCH v2 26/35] cifs: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 fs/cifs/smb2pdu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 75311a8a68bf..ab8dc73d2282 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -2550,12 +2550,11 @@ SMB2_ioctl_init(struct cifs_tcon *tcon, struct smb_rqst 
*rqst,
 * indatalen is usually small at a couple of bytes max, so
 * just allocate through generic pool
 */
-   in_data_buf = kmalloc(indatalen, GFP_NOFS);
+   in_data_buf = kmemdup(in_data, indatalen, GFP_NOFS);
if (!in_data_buf) {
cifs_small_buf_release(req);
return -ENOMEM;
}
-   memcpy(in_data_buf, in_data, indatalen);
}
 
req->CtlCode = cpu_to_le32(opcode);
-- 
2.11.0



[PATCH v2 25/35] usb: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/usb/class/cdc-acm.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 183b41753c98..cc4a96d59ffc 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -1410,12 +1410,11 @@ static int acm_probe(struct usb_interface *intf,
struct usb_cdc_country_functional_desc * cfd =
h.usb_cdc_country_functional_desc;
 
-   acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL);
+   acm->country_codes = kmemdup((u8 *)>wCountyCode0,
+   cfd->bLength - 4, GFP_KERNEL);
if (!acm->country_codes)
goto skip_countries;
acm->country_code_size = cfd->bLength - 4;
-   memcpy(acm->country_codes, (u8 *)>wCountyCode0,
-   cfd->bLength - 4);
acm->country_rel_date = cfd->iCountryCodeRelDate;
 
i = device_create_file(>dev, _attr_wCountryCodes);
-- 
2.11.0



[PATCH v2 24/35] scsi/qla4xxx: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/scsi/qla4xxx/ql4_os.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index 8c674eca09f1..8f8c64e5f02d 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -3559,21 +3559,18 @@ static int qla4xxx_copy_from_fwddb_param(struct 
iscsi_bus_flash_session *sess,
conn->port = le16_to_cpu(fw_ddb_entry->port);
 
options = le16_to_cpu(fw_ddb_entry->options);
-   conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
+   conn->ipaddress = kmemdup(fw_ddb_entry->ip_addr, IPv6_ADDR_LEN, 
GFP_KERNEL);
if (!conn->ipaddress) {
rc = -ENOMEM;
goto exit_copy;
}
 
-   conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
+   conn->redirect_ipaddr = kmemdup(fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN, 
GFP_KERNEL);
if (!conn->redirect_ipaddr) {
rc = -ENOMEM;
goto exit_copy;
}
 
-   memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
-   memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
-
if (test_bit(OPT_IPV6_DEVICE, )) {
conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
 
-- 
2.11.0



[PATCH v2 22/35] scsi/aic7xxx: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/scsi/aic7xxx/aic79xx_core.c | 3 +--
 drivers/scsi/aic7xxx/aic7xxx_core.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/aic7xxx/aic79xx_core.c 
b/drivers/scsi/aic7xxx/aic79xx_core.c
index 7e5044bf05c0..f4bc88c50dcd 100644
--- a/drivers/scsi/aic7xxx/aic79xx_core.c
+++ b/drivers/scsi/aic7xxx/aic79xx_core.c
@@ -9442,10 +9442,9 @@ ahd_loadseq(struct ahd_softc *ahd)
if (cs_count != 0) {
 
cs_count *= sizeof(struct cs);
-   ahd->critical_sections = kmalloc(cs_count, GFP_ATOMIC);
+   ahd->critical_sections = kmemdup(cs_table, cs_count, 
GFP_ATOMIC);
if (ahd->critical_sections == NULL)
panic("ahd_loadseq: Could not malloc");
-   memcpy(ahd->critical_sections, cs_table, cs_count);
}
ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE);
 
diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c 
b/drivers/scsi/aic7xxx/aic7xxx_core.c
index a9d40d3b90ef..7ea4e45309ff 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_core.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_core.c
@@ -6907,10 +6907,9 @@ ahc_loadseq(struct ahc_softc *ahc)
if (cs_count != 0) {
 
cs_count *= sizeof(struct cs);
-   ahc->critical_sections = kmalloc(cs_count, GFP_ATOMIC);
+   ahc->critical_sections = kmemdup(cs_table, cs_count, 
GFP_ATOMIC);
if (ahc->critical_sections == NULL)
panic("ahc_loadseq: Could not malloc");
-   memcpy(ahc->critical_sections, cs_table, cs_count);
}
ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE);
 
-- 
2.11.0



[PATCH v2 23/35] scsi: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/scsi/myrb.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/scsi/myrb.c b/drivers/scsi/myrb.c
index 539ac8ce4fcd..5e6b5e7ae93a 100644
--- a/drivers/scsi/myrb.c
+++ b/drivers/scsi/myrb.c
@@ -1658,14 +1658,12 @@ static int myrb_ldev_slave_alloc(struct scsi_device 
*sdev)
if (!ldev_info)
return -ENXIO;
 
-   sdev->hostdata = kzalloc(sizeof(*ldev_info), GFP_KERNEL);
+   sdev->hostdata = kmemdup(ldev_info, sizeof(*ldev_info), GFP_KERNEL);
if (!sdev->hostdata)
return -ENOMEM;
dev_dbg(>sdev_gendev,
"slave alloc ldev %d state %x\n",
ldev_num, ldev_info->state);
-   memcpy(sdev->hostdata, ldev_info,
-  sizeof(*ldev_info));
switch (ldev_info->raid_level) {
case MYRB_RAID_LEVEL0:
level = RAID_LEVEL_LINEAR;
-- 
2.11.0



[PATCH v2 20/35] platform/x86/asus: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)
  - Split into two patches.

 drivers/platform/x86/asus-wmi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index 9b18a184e0aa..472b317ad814 100644
--- a/drivers/platform/x86/asus-wmi.c
+++ b/drivers/platform/x86/asus-wmi.c
@@ -260,12 +260,11 @@ static int asus_wmi_evaluate_method_agfn(const struct 
acpi_buffer args)
 * Copy to dma capable address otherwise memory corruption occurs as
 * bios has to be able to access it.
 */
-   input.pointer = kzalloc(args.length, GFP_DMA | GFP_KERNEL);
+   input.pointer = kmemdup(args.pointer, args.length, GFP_DMA | 
GFP_KERNEL);
input.length = args.length;
if (!input.pointer)
return -ENOMEM;
phys_addr = virt_to_phys(input.pointer);
-   memcpy(input.pointer, args.pointer, args.length);
 
status = asus_wmi_evaluate_method(ASUS_WMI_METHODID_AGFN,
phys_addr, 0, );
-- 
2.11.0



[PATCH v2 21/35] platform/x86/thinkpad: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/platform/x86/thinkpad_acpi.c | 17 +++--
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/platform/x86/thinkpad_acpi.c 
b/drivers/platform/x86/thinkpad_acpi.c
index 7bde4640ef34..d379bdf98a0f 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3647,22 +3647,19 @@ static int __init hotkey_init(struct ibm_init_struct 
*iibm)
goto err_exit;
 
/* Set up key map */
-   hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE,
-   GFP_KERNEL);
-   if (!hotkey_keycode_map) {
-   pr_err("failed to allocate memory for key map\n");
-   res = -ENOMEM;
-   goto err_exit;
-   }
-
keymap_id = tpacpi_check_quirks(tpacpi_keymap_qtable,
ARRAY_SIZE(tpacpi_keymap_qtable));
BUG_ON(keymap_id >= ARRAY_SIZE(tpacpi_keymaps));
dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
   "using keymap number %lu\n", keymap_id);
 
-   memcpy(hotkey_keycode_map, _keymaps[keymap_id],
-   TPACPI_HOTKEY_MAP_SIZE);
+   hotkey_keycode_map = kmemdup(_keymaps[keymap_id],
+   TPACPI_HOTKEY_MAP_SIZE, GFP_KERNEL);
+   if (!hotkey_keycode_map) {
+   pr_err("failed to allocate memory for key map\n");
+   res = -ENOMEM;
+   goto err_exit;
+   }
 
input_set_capability(tpacpi_inputdev, EV_MSC, MSC_SCAN);
tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE;
-- 
2.11.0



[PATCH v2 19/35] pcmcia: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/pcmcia/cistpl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c
index abd029945cc8..eff91726f121 100644
--- a/drivers/pcmcia/cistpl.c
+++ b/drivers/pcmcia/cistpl.c
@@ -414,14 +414,13 @@ int pcmcia_replace_cis(struct pcmcia_socket *s,
}
mutex_lock(>ops_mutex);
kfree(s->fake_cis);
-   s->fake_cis = kmalloc(len, GFP_KERNEL);
+   s->fake_cis = kmemdup(data, len, GFP_KERNEL);
if (s->fake_cis == NULL) {
dev_warn(>dev, "no memory to replace CIS\n");
mutex_unlock(>ops_mutex);
return -ENOMEM;
}
s->fake_cis_len = len;
-   memcpy(s->fake_cis, data, len);
dev_info(>dev, "Using replacement CIS\n");
mutex_unlock(>ops_mutex);
return 0;
-- 
2.11.0



[PATCH v2 14/35] message/fusion: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/message/fusion/mptbase.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index d8882b0a1338..e0c57cecddd3 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -6001,13 +6001,12 @@ mpt_findImVolumes(MPT_ADAPTER *ioc)
if (mpt_config(ioc, ) != 0)
goto out;
 
-   mem = kmalloc(iocpage2sz, GFP_KERNEL);
+   mem = kmemdup((u8 *)pIoc2, iocpage2sz, GFP_KERNEL);
if (!mem) {
rc = -ENOMEM;
goto out;
}
 
-   memcpy(mem, (u8 *)pIoc2, iocpage2sz);
ioc->raid_data.pIocPg2 = (IOCPage2_t *) mem;
 
mpt_read_ioc_pg_3(ioc);
-- 
2.11.0



[PATCH v2 17/35] net/wireless: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/net/wireless/ath/ath6kl/wmi.c  | 6 ++
 drivers/net/wireless/st/cw1200/queue.c | 3 +--
 drivers/net/wireless/ti/wlcore/main.c  | 3 +--
 3 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wireless/ath/ath6kl/wmi.c 
b/drivers/net/wireless/ath/ath6kl/wmi.c
index 68854c45d0a4..7452a0f587fe 100644
--- a/drivers/net/wireless/ath/ath6kl/wmi.c
+++ b/drivers/net/wireless/ath/ath6kl/wmi.c
@@ -3643,7 +3643,7 @@ static int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 
if_idx, u32 id,
if (wait)
return -EINVAL; /* Offload for wait not supported */
 
-   buf = kmalloc(data_len, GFP_KERNEL);
+   buf = kmemdup(data, data_len, GFP_KERNEL);
if (!buf)
return -ENOMEM;
 
@@ -3654,7 +3654,6 @@ static int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 
if_idx, u32 id,
}
 
kfree(wmi->last_mgmt_tx_frame);
-   memcpy(buf, data, data_len);
wmi->last_mgmt_tx_frame = buf;
wmi->last_mgmt_tx_frame_len = data_len;
 
@@ -3682,7 +3681,7 @@ static int __ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 
if_idx, u32 id,
if (wait)
return -EINVAL; /* Offload for wait not supported */
 
-   buf = kmalloc(data_len, GFP_KERNEL);
+   buf = kmemdup(data, data_len, GFP_KERNEL);
if (!buf)
return -ENOMEM;
 
@@ -3693,7 +3692,6 @@ static int __ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 
if_idx, u32 id,
}
 
kfree(wmi->last_mgmt_tx_frame);
-   memcpy(buf, data, data_len);
wmi->last_mgmt_tx_frame = buf;
wmi->last_mgmt_tx_frame_len = data_len;
 
diff --git a/drivers/net/wireless/st/cw1200/queue.c 
b/drivers/net/wireless/st/cw1200/queue.c
index 14133eedb3b6..12952b1c29df 100644
--- a/drivers/net/wireless/st/cw1200/queue.c
+++ b/drivers/net/wireless/st/cw1200/queue.c
@@ -79,10 +79,9 @@ static void cw1200_queue_register_post_gc(struct list_head 
*gc_list,
  struct cw1200_queue_item *item)
 {
struct cw1200_queue_item *gc_item;
-   gc_item = kmalloc(sizeof(struct cw1200_queue_item),
+   gc_item = kmemdup(item, sizeof(struct cw1200_queue_item),
GFP_ATOMIC);
BUG_ON(!gc_item);
-   memcpy(gc_item, item, sizeof(struct cw1200_queue_item));
list_add_tail(_item->head, gc_list);
 }
 
diff --git a/drivers/net/wireless/ti/wlcore/main.c 
b/drivers/net/wireless/ti/wlcore/main.c
index c9a485ecee7b..297207856494 100644
--- a/drivers/net/wireless/ti/wlcore/main.c
+++ b/drivers/net/wireless/ti/wlcore/main.c
@@ -1434,7 +1434,7 @@ int wl1271_rx_filter_alloc_field(struct wl12xx_rx_filter 
*filter,
 
field = >fields[filter->num_fields];
 
-   field->pattern = kzalloc(len, GFP_KERNEL);
+   field->pattern = kmemdup(pattern, len, GFP_KERNEL);
if (!field->pattern) {
wl1271_warning("Failed to allocate RX filter pattern");
return -ENOMEM;
@@ -1445,7 +1445,6 @@ int wl1271_rx_filter_alloc_field(struct wl12xx_rx_filter 
*filter,
field->offset = cpu_to_le16(offset);
field->flags = flags;
field->len = len;
-   memcpy(field->pattern, pattern, len);
 
return 0;
 }
-- 
2.11.0



[PATCH v2 15/35] net/ethernet: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/net/ethernet/mellanox/mlx4/resource_tracker.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c 
b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
index 4356f3a58002..e971a6bdf0d5 100644
--- a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
+++ b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
@@ -4437,14 +4437,13 @@ int mlx4_QP_FLOW_STEERING_ATTACH_wrapper(struct 
mlx4_dev *dev, int slave,
goto err_detach;
 
mbox_size = qp_attach_mbox_size(inbox->buf);
-   rrule->mirr_mbox = kmalloc(mbox_size, GFP_KERNEL);
+   rrule->mirr_mbox = kmemdup(inbox->buf, mbox_size, GFP_KERNEL);
if (!rrule->mirr_mbox) {
err = -ENOMEM;
goto err_put_rule;
}
rrule->mirr_mbox_size = mbox_size;
rrule->mirr_rule_id = 0;
-   memcpy(rrule->mirr_mbox, inbox->buf, mbox_size);
 
/* set different port */
ctrl = (struct mlx4_net_trans_rule_hw_ctrl *)rrule->mirr_mbox;
-- 
2.11.0



[PATCH v2 16/35] net/wimax: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/net/wimax/i2400m/usb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/wimax/i2400m/usb.c b/drivers/net/wimax/i2400m/usb.c
index 2075e7b1fff6..cdce6c47c444 100644
--- a/drivers/net/wimax/i2400m/usb.c
+++ b/drivers/net/wimax/i2400m/usb.c
@@ -155,12 +155,11 @@ int __i2400mu_send_barker(struct i2400mu *i2400mu,
do_autopm = 0;
}
ret = -ENOMEM;
-   buffer = kmalloc(barker_size, GFP_KERNEL);
+   buffer = kmemdup(barker, barker_size, GFP_KERNEL);
if (buffer == NULL)
goto error_kzalloc;
epd = usb_get_epd(i2400mu->usb_iface, endpoint);
pipe = usb_sndbulkpipe(i2400mu->usb_dev, epd->bEndpointAddress);
-   memcpy(buffer, barker, barker_size);
 retry:
ret = usb_bulk_msg(i2400mu->usb_dev, pipe, buffer, barker_size,
   _len, 200);
-- 
2.11.0



[PATCH v2 11/35] media/dvb: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/media/dvb-core/dvbdev.c | 3 +--
 drivers/media/dvb-frontends/drx39xyj/drxj.c | 5 ++---
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index a3393cd4e584..e4abe8d34535 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -476,7 +476,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct 
dvb_device **pdvbdev,
return -ENOMEM;
}
 
-   dvbdevfops = kzalloc(sizeof(struct file_operations), GFP_KERNEL);
+   dvbdevfops = kmemdup(template->fops, sizeof(struct file_operations), 
GFP_KERNEL);
 
if (!dvbdevfops){
kfree (dvbdev);
@@ -492,7 +492,6 @@ int dvb_register_device(struct dvb_adapter *adap, struct 
dvb_device **pdvbdev,
dvbdev->fops = dvbdevfops;
init_waitqueue_head (>wait_queue);
 
-   memcpy(dvbdevfops, template->fops, sizeof(struct file_operations));
dvbdevfops->owner = adap->module;
 
list_add_tail (>list_head, >device_list);
diff --git a/drivers/media/dvb-frontends/drx39xyj/drxj.c 
b/drivers/media/dvb-frontends/drx39xyj/drxj.c
index a6876fa48753..2f5af4813a74 100644
--- a/drivers/media/dvb-frontends/drx39xyj/drxj.c
+++ b/drivers/media/dvb-frontends/drx39xyj/drxj.c
@@ -12287,7 +12287,8 @@ struct dvb_frontend *drx39xxj_attach(struct i2c_adapter 
*i2c)
if (state == NULL)
goto error;
 
-   demod = kmalloc(sizeof(struct drx_demod_instance), GFP_KERNEL);
+   demod = kmemdup(_default_demod_g,
+   sizeof(struct drx_demod_instance), GFP_KERNEL);
if (demod == NULL)
goto error;
 
@@ -12311,8 +12312,6 @@ struct dvb_frontend *drx39xxj_attach(struct i2c_adapter 
*i2c)
state->demod = demod;
 
/* setup the demod data */
-   memcpy(demod, _default_demod_g, sizeof(struct drx_demod_instance));
-
demod->my_i2c_dev_addr = demod_addr;
demod->my_common_attr = demod_comm_attr;
demod->my_i2c_dev_addr->user_data = state;
-- 
2.11.0



[PATCH v2 12/35] media/tuners: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/media/tuners/tuner-xc2028.c | 3 +--
 drivers/media/tuners/xc4000.c   | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/tuners/tuner-xc2028.c 
b/drivers/media/tuners/tuner-xc2028.c
index aa6861dcd3fd..574c3bb135d7 100644
--- a/drivers/media/tuners/tuner-xc2028.c
+++ b/drivers/media/tuners/tuner-xc2028.c
@@ -381,7 +381,7 @@ static int load_all_firmwares(struct dvb_frontend *fe,
goto corrupt;
}
 
-   priv->firm[n].ptr = kzalloc(size, GFP_KERNEL);
+   priv->firm[n].ptr = kmemdup(p, size, GFP_KERNEL);
if (priv->firm[n].ptr == NULL) {
tuner_err("Not enough memory to load firmware file.\n");
rc = -ENOMEM;
@@ -394,7 +394,6 @@ static int load_all_firmwares(struct dvb_frontend *fe,
   type, (unsigned long long)id, size);
}
 
-   memcpy(priv->firm[n].ptr, p, size);
priv->firm[n].type = type;
priv->firm[n].id   = id;
priv->firm[n].size = size;
diff --git a/drivers/media/tuners/xc4000.c b/drivers/media/tuners/xc4000.c
index 43925e219d81..d9606738ce43 100644
--- a/drivers/media/tuners/xc4000.c
+++ b/drivers/media/tuners/xc4000.c
@@ -812,7 +812,7 @@ static int xc4000_fwupload(struct dvb_frontend *fe)
goto corrupt;
}
 
-   priv->firm[n].ptr = kzalloc(size, GFP_KERNEL);
+   priv->firm[n].ptr = kmemdup(p, size, GFP_KERNEL);
if (priv->firm[n].ptr == NULL) {
printk(KERN_ERR "Not enough memory to load firmware 
file.\n");
rc = -ENOMEM;
@@ -826,7 +826,6 @@ static int xc4000_fwupload(struct dvb_frontend *fe)
   type, (unsigned long long)id, size);
}
 
-   memcpy(priv->firm[n].ptr, p, size);
priv->firm[n].type = type;
priv->firm[n].id   = id;
priv->firm[n].size = size;
-- 
2.11.0



[PATCH v2 10/35] macintosh: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/macintosh/adbhid.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/macintosh/adbhid.c b/drivers/macintosh/adbhid.c
index 75482eeab2c4..5d14bebfb58f 100644
--- a/drivers/macintosh/adbhid.c
+++ b/drivers/macintosh/adbhid.c
@@ -789,7 +789,8 @@ adbhid_input_register(int id, int default_id, int 
original_handler_id,
 
switch (default_id) {
case ADB_KEYBOARD:
-   hid->keycode = kmalloc(sizeof(adb_to_linux_keycodes), 
GFP_KERNEL);
+   hid->keycode = kmemdup(adb_to_linux_keycodes,
+   sizeof(adb_to_linux_keycodes), GFP_KERNEL);
if (!hid->keycode) {
err = -ENOMEM;
goto fail;
@@ -797,8 +798,6 @@ adbhid_input_register(int id, int default_id, int 
original_handler_id,
 
sprintf(hid->name, "ADB keyboard");
 
-   memcpy(hid->keycode, adb_to_linux_keycodes, 
sizeof(adb_to_linux_keycodes));
-
switch (original_handler_id) {
default:
keyboard_type = "";
-- 
2.11.0



[PATCH v2 13/35] media/usb: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/media/usb/em28xx/em28xx-cards.c | 3 +--
 drivers/media/usb/zr364xx/zr364xx.c | 4 +---
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-cards.c 
b/drivers/media/usb/em28xx/em28xx-cards.c
index 1283c7ca9ad5..6e33782c3ca6 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -3566,13 +3566,12 @@ static int em28xx_init_dev(struct em28xx *dev, struct 
usb_device *udev,
 static int em28xx_duplicate_dev(struct em28xx *dev)
 {
int nr;
-   struct em28xx *sec_dev = kzalloc(sizeof(*sec_dev), GFP_KERNEL);
+   struct em28xx *sec_dev = kmemdup(dev, sizeof(*sec_dev), GFP_KERNEL);
 
if (!sec_dev) {
dev->dev_next = NULL;
return -ENOMEM;
}
-   memcpy(sec_dev, dev, sizeof(*sec_dev));
/* Check to see next free device and mark as used */
do {
nr = find_first_zero_bit(em28xx_devused, EM28XX_MAXBOARDS);
diff --git a/drivers/media/usb/zr364xx/zr364xx.c 
b/drivers/media/usb/zr364xx/zr364xx.c
index 37a7992585df..39df6bfece2c 100644
--- a/drivers/media/usb/zr364xx/zr364xx.c
+++ b/drivers/media/usb/zr364xx/zr364xx.c
@@ -199,12 +199,10 @@ static int send_control_msg(struct usb_device *udev, u8 
request, u16 value,
 {
int status;
 
-   unsigned char *transfer_buffer = kmalloc(size, GFP_KERNEL);
+   unsigned char *transfer_buffer = kmemdup(cp, size, GFP_KERNEL);
if (!transfer_buffer)
return -ENOMEM;
 
-   memcpy(transfer_buffer, cp, size);
-
status = usb_control_msg(udev,
 usb_sndctrlpipe(udev, 0),
 request,
-- 
2.11.0



[PATCH v2 08/35] drm/i915: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/gpu/drm/i915/gvt/dmabuf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/gvt/dmabuf.c 
b/drivers/gpu/drm/i915/gvt/dmabuf.c
index 41c8ebc60c63..fe6fa979f22a 100644
--- a/drivers/gpu/drm/i915/gvt/dmabuf.c
+++ b/drivers/gpu/drm/i915/gvt/dmabuf.c
@@ -411,14 +411,13 @@ int intel_vgpu_query_plane(struct intel_vgpu *vgpu, void 
*args)
goto out;
}
 
-   dmabuf_obj->info = kmalloc(sizeof(struct intel_vgpu_fb_info),
+   dmabuf_obj->info = kmemdup(_info, sizeof(struct intel_vgpu_fb_info),
   GFP_KERNEL);
if (unlikely(!dmabuf_obj->info)) {
gvt_vgpu_err("allocate intel vgpu fb info failed\n");
ret = -ENOMEM;
goto out_free_dmabuf;
}
-   memcpy(dmabuf_obj->info, _info, sizeof(struct intel_vgpu_fb_info));
 
((struct intel_vgpu_fb_info *)dmabuf_obj->info)->obj = dmabuf_obj;
 
-- 
2.11.0



[PATCH v2 07/35] drm/amdgpu: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Reviewed-by: Emil Velikov 
Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c   | 5 ++---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c   | 5 ++---
 drivers/gpu/drm/amd/display/dc/core/dc.c| 6 ++
 drivers/gpu/drm/amd/display/dc/core/dc_stream.c | 4 +---
 4 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
index 02955e6e9dd9..48e38479d634 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
@@ -3925,11 +3925,10 @@ static int gfx_v8_0_init_save_restore_list(struct 
amdgpu_device *adev)
 
int list_size;
unsigned int *register_list_format =
-   kmalloc(adev->gfx.rlc.reg_list_format_size_bytes, GFP_KERNEL);
+   kmemdup(adev->gfx.rlc.register_list_format,
+   adev->gfx.rlc.reg_list_format_size_bytes, GFP_KERNEL);
if (!register_list_format)
return -ENOMEM;
-   memcpy(register_list_format, adev->gfx.rlc.register_list_format,
-   adev->gfx.rlc.reg_list_format_size_bytes);
 
gfx_v8_0_parse_ind_reg_list(register_list_format,
RLC_FormatDirectRegListLength,
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
index b610e3b30d95..09d901ef216d 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
@@ -2092,11 +2092,10 @@ static int gfx_v9_1_init_rlc_save_restore_list(struct 
amdgpu_device *adev)
u32 tmp = 0;
 
u32 *register_list_format =
-   kmalloc(adev->gfx.rlc.reg_list_format_size_bytes, GFP_KERNEL);
+   kmemdup(adev->gfx.rlc.register_list_format,
+   adev->gfx.rlc.reg_list_format_size_bytes, GFP_KERNEL);
if (!register_list_format)
return -ENOMEM;
-   memcpy(register_list_format, adev->gfx.rlc.register_list_format,
-   adev->gfx.rlc.reg_list_format_size_bytes);
 
/* setup unique_indirect_regs array and indirect_start_offsets array */
unique_indirect_reg_count = ARRAY_SIZE(unique_indirect_regs);
diff --git a/drivers/gpu/drm/amd/display/dc/core/dc.c 
b/drivers/gpu/drm/amd/display/dc/core/dc.c
index 18c775a950cc..6ced3b9cdce2 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc.c
@@ -1263,14 +1263,12 @@ struct dc_state *dc_create_state(struct dc *dc)
 struct dc_state *dc_copy_state(struct dc_state *src_ctx)
 {
int i, j;
-   struct dc_state *new_ctx = kzalloc(sizeof(struct dc_state),
-  GFP_KERNEL);
+   struct dc_state *new_ctx = kmemdup(src_ctx,
+   sizeof(struct dc_state), GFP_KERNEL);
 
if (!new_ctx)
return NULL;
 
-   memcpy(new_ctx, src_ctx, sizeof(struct dc_state));
-
for (i = 0; i < MAX_PIPES; i++) {
struct pipe_ctx *cur_pipe = 
_ctx->res_ctx.pipe_ctx[i];
 
diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_stream.c 
b/drivers/gpu/drm/amd/display/dc/core/dc_stream.c
index 96e97d25d639..d4b563a2e220 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc_stream.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc_stream.c
@@ -167,12 +167,10 @@ struct dc_stream_state *dc_copy_stream(const struct 
dc_stream_state *stream)
 {
struct dc_stream_state *new_stream;
 
-   new_stream = kzalloc(sizeof(struct dc_stream_state), GFP_KERNEL);
+   new_stream = kzalloc(stream, sizeof(struct dc_stream_state), 
GFP_KERNEL);
if (!new_stream)
return NULL;
 
-   memcpy(new_stream, stream, sizeof(struct dc_stream_state));
-
if (new_stream->sink)
dc_sink_retain(new_stream->sink);
 
-- 
2.11.0



[PATCH v2 09/35] infiniband: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/infiniband/hw/i40iw/i40iw_cm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/hw/i40iw/i40iw_cm.c 
b/drivers/infiniband/hw/i40iw/i40iw_cm.c
index 8233f5a4e623..84b3ff2687fb 100644
--- a/drivers/infiniband/hw/i40iw/i40iw_cm.c
+++ b/drivers/infiniband/hw/i40iw/i40iw_cm.c
@@ -4276,11 +4276,11 @@ static void i40iw_qhash_ctrl(struct i40iw_device *iwdev,
/* if not found then add a child listener if interface is going up */
if (!ifup)
return;
-   child_listen_node = kzalloc(sizeof(*child_listen_node), GFP_ATOMIC);
+   child_listen_node = kmemdup(parent_listen_node,
+   sizeof(*child_listen_node), GFP_ATOMIC);
if (!child_listen_node)
return;
node_allocated = true;
-   memcpy(child_listen_node, parent_listen_node, 
sizeof(*child_listen_node));
 
memcpy(child_listen_node->loc_addr, ipaddr,  ipv4 ? 4 : 16);
 
-- 
2.11.0



[PATCH v2 02/35] powerpc: Add an allocation failure check

2019-07-03 Thread Fuqian Huang
Add an allocation failure check.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Split into two patches

 arch/powerpc/platforms/pseries/dlpar.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/platforms/pseries/dlpar.c 
b/arch/powerpc/platforms/pseries/dlpar.c
index 437a74173db2..7488e40f5e47 100644
--- a/arch/powerpc/platforms/pseries/dlpar.c
+++ b/arch/powerpc/platforms/pseries/dlpar.c
@@ -385,6 +385,8 @@ void queue_hotplug_event(struct pseries_hp_errorlog 
*hp_errlog)
 
hp_errlog_copy = kmalloc(sizeof(struct pseries_hp_errorlog),
 GFP_KERNEL);
+   if (!hp_errlog_copy)
+ return;
memcpy(hp_errlog_copy, hp_errlog, sizeof(struct pseries_hp_errorlog));
 
work = kmalloc(sizeof(struct pseries_hp_work), GFP_KERNEL);
-- 
2.11.0



[PATCH v2 04/35] block: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/block/rbd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index e5009a34f9c2..47ad3772dc58 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -1068,7 +1068,7 @@ static int rbd_header_from_disk(struct rbd_device 
*rbd_dev,
 
if (snap_names_len > (u64)SIZE_MAX)
goto out_2big;
-   snap_names = kmalloc(snap_names_len, GFP_KERNEL);
+   snap_names = kmemdup(>snaps[snap_count], 
snap_names_len, GFP_KERNEL);
if (!snap_names)
goto out_err;
 
@@ -1088,7 +1088,6 @@ static int rbd_header_from_disk(struct rbd_device 
*rbd_dev,
 * snap_names_len bytes beyond the end of the
 * snapshot id array, this memcpy() is safe.
 */
-   memcpy(snap_names, >snaps[snap_count], snap_names_len);
snaps = ondisk->snaps;
for (i = 0; i < snap_count; i++) {
snapc->snaps[i] = le64_to_cpu(snaps[i].id);
-- 
2.11.0



[PATCH v2 06/35] crypto: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/crypto/caam/caampkc.c  | 11 +++
 drivers/crypto/virtio/virtio_crypto_algs.c |  4 +---
 2 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c
index fe24485274e1..a03464b4c019 100644
--- a/drivers/crypto/caam/caampkc.c
+++ b/drivers/crypto/caam/caampkc.c
@@ -816,7 +816,7 @@ static int caam_rsa_set_pub_key(struct crypto_akcipher 
*tfm, const void *key,
return ret;
 
/* Copy key in DMA zone */
-   rsa_key->e = kzalloc(raw_key.e_sz, GFP_DMA | GFP_KERNEL);
+   rsa_key->e = kmemdup(raw_key.e, raw_key.e_sz, GFP_DMA | GFP_KERNEL);
if (!rsa_key->e)
goto err;
 
@@ -838,8 +838,6 @@ static int caam_rsa_set_pub_key(struct crypto_akcipher 
*tfm, const void *key,
rsa_key->e_sz = raw_key.e_sz;
rsa_key->n_sz = raw_key.n_sz;
 
-   memcpy(rsa_key->e, raw_key.e, raw_key.e_sz);
-
return 0;
 err:
caam_rsa_free_key(rsa_key);
@@ -920,11 +918,11 @@ static int caam_rsa_set_priv_key(struct crypto_akcipher 
*tfm, const void *key,
return ret;
 
/* Copy key in DMA zone */
-   rsa_key->d = kzalloc(raw_key.d_sz, GFP_DMA | GFP_KERNEL);
+   rsa_key->d = kmemdup(raw_key.d, raw_key.d_sz, GFP_DMA | GFP_KERNEL);
if (!rsa_key->d)
goto err;
 
-   rsa_key->e = kzalloc(raw_key.e_sz, GFP_DMA | GFP_KERNEL);
+   rsa_key->e = kmemdup(raw_key.e, raw_key.e_sz, GFP_DMA | GFP_KERNEL);
if (!rsa_key->e)
goto err;
 
@@ -947,9 +945,6 @@ static int caam_rsa_set_priv_key(struct crypto_akcipher 
*tfm, const void *key,
rsa_key->e_sz = raw_key.e_sz;
rsa_key->n_sz = raw_key.n_sz;
 
-   memcpy(rsa_key->d, raw_key.d, raw_key.d_sz);
-   memcpy(rsa_key->e, raw_key.e, raw_key.e_sz);
-
caam_rsa_set_priv_key_form(ctx, _key);
 
return 0;
diff --git a/drivers/crypto/virtio/virtio_crypto_algs.c 
b/drivers/crypto/virtio/virtio_crypto_algs.c
index 10f266d462d6..42d19205166b 100644
--- a/drivers/crypto/virtio/virtio_crypto_algs.c
+++ b/drivers/crypto/virtio/virtio_crypto_algs.c
@@ -129,13 +129,11 @@ static int virtio_crypto_alg_ablkcipher_init_session(
 * Avoid to do DMA from the stack, switch to using
 * dynamically-allocated for the key
 */
-   uint8_t *cipher_key = kmalloc(keylen, GFP_ATOMIC);
+   uint8_t *cipher_key = kmemdup(key, keylen, GFP_ATOMIC);
 
if (!cipher_key)
return -ENOMEM;
 
-   memcpy(cipher_key, key, keylen);
-
spin_lock(>ctrl_lock);
/* Pad ctrl header */
vcrypto->ctrl.header.opcode =
-- 
2.11.0



[PATCH v2 03/35] powerpc: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 arch/powerpc/platforms/pseries/dlpar.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/dlpar.c 
b/arch/powerpc/platforms/pseries/dlpar.c
index 7488e40f5e47..20fe7b79e09e 100644
--- a/arch/powerpc/platforms/pseries/dlpar.c
+++ b/arch/powerpc/platforms/pseries/dlpar.c
@@ -383,11 +383,10 @@ void queue_hotplug_event(struct pseries_hp_errorlog 
*hp_errlog)
struct pseries_hp_work *work;
struct pseries_hp_errorlog *hp_errlog_copy;
 
-   hp_errlog_copy = kmalloc(sizeof(struct pseries_hp_errorlog),
+   hp_errlog_copy = kmemdup(hp_errlog, sizeof(struct pseries_hp_errorlog),
 GFP_KERNEL);
if (!hp_errlog_copy)
  return;
-   memcpy(hp_errlog_copy, hp_errlog, sizeof(struct pseries_hp_errorlog));
 
work = kmalloc(sizeof(struct pseries_hp_work), GFP_KERNEL);
if (work) {
-- 
2.11.0



[PATCH v2 05/35] clk/ti: Use kmemdup rather than duplicating its implementation

2019-07-03 Thread Fuqian Huang
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang 
---
Changes in v2:
  - Fix a typo in commit message (memset -> memcpy)

 drivers/clk/ti/dpll.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/clk/ti/dpll.c b/drivers/clk/ti/dpll.c
index 659dadb23279..f728d987ebac 100644
--- a/drivers/clk/ti/dpll.c
+++ b/drivers/clk/ti/dpll.c
@@ -291,14 +291,12 @@ static void __init of_ti_dpll_setup(struct device_node 
*node,
struct dpll_data *dd = NULL;
u8 dpll_mode = 0;
 
-   dd = kzalloc(sizeof(*dd), GFP_KERNEL);
+   dd = kmemdup(ddt, sizeof(*dd), GFP_KERNEL);
clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL);
init = kzalloc(sizeof(*init), GFP_KERNEL);
if (!dd || !clk_hw || !init)
goto cleanup;
 
-   memcpy(dd, ddt, sizeof(*dd));
-
clk_hw->dpll_data = dd;
clk_hw->ops = _omap3_dpll;
clk_hw->hw.init = init;
-- 
2.11.0



  1   2   3   >