[PATCH] percpu_counter: Add NULL check to prevent crash in __percpu_counter_add

2017-05-16 Thread Niranjan Dighe
From: Niranjan Dighe <ndi...@visteon.com>

Following kernel crash was observed because of a possible race condition in
block layer that passes struct percpu_counter *fcp with fcp->counters field
NULL. Added extra checks to prevent similar crashes because of bugs in the
upper layers.

This is fairly easy to reproduce with kernel 4.1.15+ when a USB device is
mounted on multiple mount points with a -B (bind) option and multiple
connection/disconnections are made repeatedly.

---

Unable to handle kernel paging request at virtual address 2ac6
pgd = a2918000
[2ac6] *pgd=
Internal error: Oops: 5 [#1] PREEMPT SMP ARM
Modules linked in: vfat fat sd_mod ntfs usb_storage scsi_mod usbhid hid
snd_usb_audio snd_hwdep snd_usbmidi_lib snd_rawmidi fuse sd8xxx(O) mlan(PO)
mmc_block spidev sdhci_esdhc_imx sdhci_pltfm sdhci spi_imx spi_bitbang ext4
jbd2 ipv6
CPU: 0 PID: 319 Comm: usbmgr Tainted: PW  O4.1.15-1.2.0+g77f6154 #2
Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
task: a23b7c00 ti: a843c000 task.ti: a843c000
PC is at __percpu_counter_add+0x34/0xf8
LR is at clear_page_dirty_for_io+0xc4/0xe0
pc : [<80213708>]lr : [<80098810>]psr: 200f0093
sp : a843de00  ip : a843de00  fp : abb6a0a0
r10: a843def8  r9 : 019b  r8 : a6020b64
r7 :   r6 : 0002  r5 :   r4 : 
r3 :   r2 : 0010  r1 : 2ac6  r0 : a8334920
Flags: nzCv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment user
Control: 10c53c7d  Table: 3291804a  DAC: 0015
Process usbmgr (pid: 319, stack limit = 0xa843c210)
Stack: (0xa843de00 to 0xa843e000)
de00: 200f0013 a6020b64 0002  a6020b64 019b a843def8 80098810
de20: 0010 8009ab24 a843de70  a843de70 8009896c 000e 
de40:   800982dc a6020b64 0002 0001 0001 a81b5e20
de60: a00f0193 08e3 0002  abb6a0a0 abc1b7c0 758045a0 80054b74
de80: 406f 8027ce94 a81b5c10 5355843b  0001 0001 4000
dea0: 0125 a81843c0 80ba11a8 a6020b64 a843def8  7fff 
dec0:   758045a0 80098be8 a843ded0 a843ded0 a843ded8 a843ded8
dee0: a843dee0 a843dee0 a6020b64 a6020b64 0001 8009064c 7fff 
df00:    7fff 0001  8000f684 a6020b64
df20: 0081  7fff 8000f684 a843c000 800906ec  7fff
df40: 0001 a23b7c00 8000f684 a6020a00 0081 80ba2ca4 a23b7c00 800cdf5c
df60: a3090c00 7f343ea4 80ba2ca4 800ce224 a2b06840  80ba2ca4 800e7aec
df80: a23b7f78 8003e124 a843c000 8000f684 a843dfb0 0034 8000f684 80012000
dfa0: 758045a8 0018 0001 8000f54c  0002 0001 76f0dcfc
dfc0: 758045a8 0018 0001 0034 aaab 00083d48 758045a0 758045a0
dfe0: 0009945c 7696dc0c 0006c31c 76b175bc 60010010 758045a8  
[<80213708>] (__percpu_counter_add) from [<80098810>] 
(clear_page_dirty_for_io+0xc4/0xe0)
[<80098810>] (clear_page_dirty_for_io) from [<8009896c>] 
(write_cache_pages+0x140/0x37c)
[<8009896c>] (write_cache_pages) from [<80098be8>] 
(generic_writepages+0x40/0x60)
[<80098be8>] (generic_writepages) from [<8009064c>] 
(__filemap_fdatawrite_range+0x64/0x6c)
[<8009064c>] (__filemap_fdatawrite_range) from [<800906ec>] 
(filemap_write_and_wait+0x38/0x64)
[<800906ec>] (filemap_write_and_wait) from [<800cdf5c>] 
(kill_block_super+0x20/0x68)
[<800cdf5c>] (kill_block_super) from [<800ce224>] 
(deactivate_locked_super+0x58/0x7c)
[<800ce224>] (deactivate_locked_super) from [<800e7aec>] (cleanup_mnt+0x38/0x7c)
[<800e7aec>] (cleanup_mnt) from [<8003e124>] (task_work_run+0xac/0xe4)
[<8003e124>] (task_work_run) from [<80012000>] (do_work_pending+0x7c/0xa4)
[<80012000>] (do_work_pending) from [<8000f54c>] (work_pending+0xc/0x20)
Code: e5813004 e5903018 e1a07fc2 ee1d1f90 (e7933001)
---[ end trace 4b693779c2eb6edd ]---

Signed-off-by: Niranjan Dighe <ndi...@visteon.com>
---
 lib/percpu_counter.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c
index f051d69..4e8c163 100644
--- a/lib/percpu_counter.c
+++ b/lib/percpu_counter.c
@@ -77,6 +77,10 @@ void __percpu_counter_add(struct percpu_counter *fbc, s64 
amount, s32 batch)
s64 count;
 
preempt_disable();
+
+   if (unlikely(!fbc->counters))
+   goto out;
+
count = __this_cpu_read(*fbc->counters) + amount;
if (count >= batch || count <= -batch) {
unsigned long flags;
@@ -87,6 +91,7 @@ void __percpu_counter_add(struct percpu_counter *fbc, s64 
amount, s32 batch)
} else {
this_cpu_add(*fbc->counters, amount);
}
+out:
preempt_enable();
 }
 EXPORT_SYMBOL(__percpu_counter_add);
-- 
2.1.4



[PATCH] percpu_counter: Add NULL check to prevent crash in __percpu_counter_add

2017-05-16 Thread Niranjan Dighe
From: Niranjan Dighe 

Following kernel crash was observed because of a possible race condition in
block layer that passes struct percpu_counter *fcp with fcp->counters field
NULL. Added extra checks to prevent similar crashes because of bugs in the
upper layers.

This is fairly easy to reproduce with kernel 4.1.15+ when a USB device is
mounted on multiple mount points with a -B (bind) option and multiple
connection/disconnections are made repeatedly.

---

Unable to handle kernel paging request at virtual address 2ac6
pgd = a2918000
[2ac6] *pgd=
Internal error: Oops: 5 [#1] PREEMPT SMP ARM
Modules linked in: vfat fat sd_mod ntfs usb_storage scsi_mod usbhid hid
snd_usb_audio snd_hwdep snd_usbmidi_lib snd_rawmidi fuse sd8xxx(O) mlan(PO)
mmc_block spidev sdhci_esdhc_imx sdhci_pltfm sdhci spi_imx spi_bitbang ext4
jbd2 ipv6
CPU: 0 PID: 319 Comm: usbmgr Tainted: PW  O4.1.15-1.2.0+g77f6154 #2
Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
task: a23b7c00 ti: a843c000 task.ti: a843c000
PC is at __percpu_counter_add+0x34/0xf8
LR is at clear_page_dirty_for_io+0xc4/0xe0
pc : [<80213708>]lr : [<80098810>]psr: 200f0093
sp : a843de00  ip : a843de00  fp : abb6a0a0
r10: a843def8  r9 : 019b  r8 : a6020b64
r7 :   r6 : 0002  r5 :   r4 : 
r3 :   r2 : 0010  r1 : 2ac6  r0 : a8334920
Flags: nzCv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment user
Control: 10c53c7d  Table: 3291804a  DAC: 0015
Process usbmgr (pid: 319, stack limit = 0xa843c210)
Stack: (0xa843de00 to 0xa843e000)
de00: 200f0013 a6020b64 0002  a6020b64 019b a843def8 80098810
de20: 0010 8009ab24 a843de70  a843de70 8009896c 000e 
de40:   800982dc a6020b64 0002 0001 0001 a81b5e20
de60: a00f0193 08e3 0002  abb6a0a0 abc1b7c0 758045a0 80054b74
de80: 406f 8027ce94 a81b5c10 5355843b  0001 0001 4000
dea0: 0125 a81843c0 80ba11a8 a6020b64 a843def8  7fff 
dec0:   758045a0 80098be8 a843ded0 a843ded0 a843ded8 a843ded8
dee0: a843dee0 a843dee0 a6020b64 a6020b64 0001 8009064c 7fff 
df00:    7fff 0001  8000f684 a6020b64
df20: 0081  7fff 8000f684 a843c000 800906ec  7fff
df40: 0001 a23b7c00 8000f684 a6020a00 0081 80ba2ca4 a23b7c00 800cdf5c
df60: a3090c00 7f343ea4 80ba2ca4 800ce224 a2b06840  80ba2ca4 800e7aec
df80: a23b7f78 8003e124 a843c000 8000f684 a843dfb0 0034 8000f684 80012000
dfa0: 758045a8 0018 0001 8000f54c  0002 0001 76f0dcfc
dfc0: 758045a8 0018 0001 0034 aaab 00083d48 758045a0 758045a0
dfe0: 0009945c 7696dc0c 0006c31c 76b175bc 60010010 758045a8  
[<80213708>] (__percpu_counter_add) from [<80098810>] 
(clear_page_dirty_for_io+0xc4/0xe0)
[<80098810>] (clear_page_dirty_for_io) from [<8009896c>] 
(write_cache_pages+0x140/0x37c)
[<8009896c>] (write_cache_pages) from [<80098be8>] 
(generic_writepages+0x40/0x60)
[<80098be8>] (generic_writepages) from [<8009064c>] 
(__filemap_fdatawrite_range+0x64/0x6c)
[<8009064c>] (__filemap_fdatawrite_range) from [<800906ec>] 
(filemap_write_and_wait+0x38/0x64)
[<800906ec>] (filemap_write_and_wait) from [<800cdf5c>] 
(kill_block_super+0x20/0x68)
[<800cdf5c>] (kill_block_super) from [<800ce224>] 
(deactivate_locked_super+0x58/0x7c)
[<800ce224>] (deactivate_locked_super) from [<800e7aec>] (cleanup_mnt+0x38/0x7c)
[<800e7aec>] (cleanup_mnt) from [<8003e124>] (task_work_run+0xac/0xe4)
[<8003e124>] (task_work_run) from [<80012000>] (do_work_pending+0x7c/0xa4)
[<80012000>] (do_work_pending) from [<8000f54c>] (work_pending+0xc/0x20)
Code: e5813004 e5903018 e1a07fc2 ee1d1f90 (e7933001)
---[ end trace 4b693779c2eb6edd ]---

Signed-off-by: Niranjan Dighe 
---
 lib/percpu_counter.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c
index f051d69..4e8c163 100644
--- a/lib/percpu_counter.c
+++ b/lib/percpu_counter.c
@@ -77,6 +77,10 @@ void __percpu_counter_add(struct percpu_counter *fbc, s64 
amount, s32 batch)
s64 count;
 
preempt_disable();
+
+   if (unlikely(!fbc->counters))
+   goto out;
+
count = __this_cpu_read(*fbc->counters) + amount;
if (count >= batch || count <= -batch) {
unsigned long flags;
@@ -87,6 +91,7 @@ void __percpu_counter_add(struct percpu_counter *fbc, s64 
amount, s32 batch)
} else {
this_cpu_add(*fbc->counters, amount);
}
+out:
preempt_enable();
 }
 EXPORT_SYMBOL(__percpu_counter_add);
-- 
2.1.4



Re: [PATCH] chipidea: Fix issue in reconnecing gadget without insmod/rmmod

2017-04-12 Thread Niranjan Dighe
On Wed, Apr 12, 2017 at 5:21 PM, Peter Chen <hzpeterc...@gmail.com> wrote:
> On Tue, Apr 11, 2017 at 08:46:24PM +0530, Niranjan Dighe wrote:
>> Currently usb_gadget_connect() is called only through gadget
>> registration via composite_driver_probe(). As a result, after a
>> disconnection, if the role transitions to host and back to gadget,
>> the gadget is not recognized by the host anymore.
>> This is a typical scenario with an iAP device in the following
>> usecase -
>> conn iAP dev -> send roleswitch command -> roleswitch ourself
>> to gadget -> disconnect iAP device -> roleswitch back to host to
>> enumerate the device again -> reconnect device -> resend the
>> roleswitch command -> roleswitch ourself to gadget -> ISSUE.
>>
>> To workaround this, do the following -
>>
>> 1. Restart OTG FSM on SLi interrupt and on switching role to gadget
>> so that device transitions to B_IDLE state from B_PERIPHERAL state.
>> A transition from B_IDLE to B_PERIPHERAL is needed to enable
>> interrups and restore the correct state of the chipidea controller
>> so that communication with host is possible
>>
>> 2. usb_gadget_connect() after roleswitch to gadget so that
>> gadget->ops->pullup() is called and D+ line is asserted. This
>> causes host to "see" the device and enumeration can happen.
>>
>> Signed-off-by: Niranjan Dighe <niranjan.di...@gmail.com>
>> ---
>>  drivers/usb/chipidea/debug.c | 10 +-
>>  drivers/usb/chipidea/udc.c   |  3 +++
>>  2 files changed, 12 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/usb/chipidea/debug.c b/drivers/usb/chipidea/debug.c
>> index a4f7db2..66c1485 100644
>> --- a/drivers/usb/chipidea/debug.c
>> +++ b/drivers/usb/chipidea/debug.c
>> @@ -16,7 +16,7 @@
>>  #include "udc.h"
>>  #include "bits.h"
>>  #include "otg.h"
>> -
>> +extern void ci_hdrc_otg_fsm_restart(struct ci_hdrc *);
>>  /**
>>   * ci_device_show: prints information about device capabilities and status
>>   */
>> @@ -325,6 +325,14 @@ static ssize_t ci_role_write(struct file *file, const 
>> char __user *ubuf,
>>   ci_role_stop(ci);
>>   ret = ci_role_start(ci, role);
>>   enable_irq(ci->irq);
>> +
>> + /* REVISIT - Avoid repeated FSM restart*/
>> +
>> + if (role == CI_ROLE_GADGET) {
>> + ci_hdrc_otg_fsm_restart(ci);
>> + usb_gadget_connect(>gadget);
>> + }
>> +
>>   pm_runtime_put_sync(ci->dev);
>>
>>   return ret ? ret : count;
>> diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
>> index a0accd5..1e3b827 100644
>> --- a/drivers/usb/chipidea/udc.c
>> +++ b/drivers/usb/chipidea/udc.c
>> @@ -29,6 +29,8 @@
>>  #include "otg.h"
>>  #include "otg_fsm.h"
>>
>> +extern void ci_hdrc_otg_fsm_restart(struct ci_hdrc *);
>> +
>>  /* control endpoint description */
>>  static const struct usb_endpoint_descriptor
>>  ctrl_endpt_out_desc = {
>> @@ -1881,6 +1883,7 @@ static irqreturn_t udc_irq(struct ci_hdrc *ci)
>>   ci->driver->suspend(>gadget);
>>   usb_gadget_set_state(>gadget,
>>   USB_STATE_SUSPENDED);
>> + ci_hdrc_otg_fsm_restart(ci);
>>   spin_lock(>lock);
>>   }
>>   }
>> --
>
> Hi Niranjan,
>
> When working with iAP device, there are two role-switch methods
> - Through OTG FSM, and using sysfs entries under
> /sys/bus/platform/devices/ci_hdrc.0/inputs
> but you may need to patch code to keep vbus always on for A-device,
> it is not compliance with OTG spec.
> - Using role interface under debugfs (I move it under sysfs for v4.12).
> But you need to patch the code and let the A-device switch back to
> host after iAP is disconnected.
>
> You don't need to use above two methods together, I suggest using the
> 2nd method since OTG FSM is hard to maintain due to no mandatory use
> case for it.
>
> --
>
> Best Regards,
> Peter Chen

Thank you Peter for your response.

Yes, I will try to switch the role on disconnection of iAP device to Host. If
I understand correctly I have to do something like this -

ci_role_stop(ci); //Gadget role stop
ret = ci_role_start(ci, role); //Host role start

correct?

Regards,
Niranjan


Re: [PATCH] chipidea: Fix issue in reconnecing gadget without insmod/rmmod

2017-04-12 Thread Niranjan Dighe
On Wed, Apr 12, 2017 at 5:21 PM, Peter Chen  wrote:
> On Tue, Apr 11, 2017 at 08:46:24PM +0530, Niranjan Dighe wrote:
>> Currently usb_gadget_connect() is called only through gadget
>> registration via composite_driver_probe(). As a result, after a
>> disconnection, if the role transitions to host and back to gadget,
>> the gadget is not recognized by the host anymore.
>> This is a typical scenario with an iAP device in the following
>> usecase -
>> conn iAP dev -> send roleswitch command -> roleswitch ourself
>> to gadget -> disconnect iAP device -> roleswitch back to host to
>> enumerate the device again -> reconnect device -> resend the
>> roleswitch command -> roleswitch ourself to gadget -> ISSUE.
>>
>> To workaround this, do the following -
>>
>> 1. Restart OTG FSM on SLi interrupt and on switching role to gadget
>> so that device transitions to B_IDLE state from B_PERIPHERAL state.
>> A transition from B_IDLE to B_PERIPHERAL is needed to enable
>> interrups and restore the correct state of the chipidea controller
>> so that communication with host is possible
>>
>> 2. usb_gadget_connect() after roleswitch to gadget so that
>> gadget->ops->pullup() is called and D+ line is asserted. This
>> causes host to "see" the device and enumeration can happen.
>>
>> Signed-off-by: Niranjan Dighe 
>> ---
>>  drivers/usb/chipidea/debug.c | 10 +-
>>  drivers/usb/chipidea/udc.c   |  3 +++
>>  2 files changed, 12 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/usb/chipidea/debug.c b/drivers/usb/chipidea/debug.c
>> index a4f7db2..66c1485 100644
>> --- a/drivers/usb/chipidea/debug.c
>> +++ b/drivers/usb/chipidea/debug.c
>> @@ -16,7 +16,7 @@
>>  #include "udc.h"
>>  #include "bits.h"
>>  #include "otg.h"
>> -
>> +extern void ci_hdrc_otg_fsm_restart(struct ci_hdrc *);
>>  /**
>>   * ci_device_show: prints information about device capabilities and status
>>   */
>> @@ -325,6 +325,14 @@ static ssize_t ci_role_write(struct file *file, const 
>> char __user *ubuf,
>>   ci_role_stop(ci);
>>   ret = ci_role_start(ci, role);
>>   enable_irq(ci->irq);
>> +
>> + /* REVISIT - Avoid repeated FSM restart*/
>> +
>> + if (role == CI_ROLE_GADGET) {
>> + ci_hdrc_otg_fsm_restart(ci);
>> + usb_gadget_connect(>gadget);
>> + }
>> +
>>   pm_runtime_put_sync(ci->dev);
>>
>>   return ret ? ret : count;
>> diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
>> index a0accd5..1e3b827 100644
>> --- a/drivers/usb/chipidea/udc.c
>> +++ b/drivers/usb/chipidea/udc.c
>> @@ -29,6 +29,8 @@
>>  #include "otg.h"
>>  #include "otg_fsm.h"
>>
>> +extern void ci_hdrc_otg_fsm_restart(struct ci_hdrc *);
>> +
>>  /* control endpoint description */
>>  static const struct usb_endpoint_descriptor
>>  ctrl_endpt_out_desc = {
>> @@ -1881,6 +1883,7 @@ static irqreturn_t udc_irq(struct ci_hdrc *ci)
>>   ci->driver->suspend(>gadget);
>>   usb_gadget_set_state(>gadget,
>>   USB_STATE_SUSPENDED);
>> + ci_hdrc_otg_fsm_restart(ci);
>>   spin_lock(>lock);
>>   }
>>   }
>> --
>
> Hi Niranjan,
>
> When working with iAP device, there are two role-switch methods
> - Through OTG FSM, and using sysfs entries under
> /sys/bus/platform/devices/ci_hdrc.0/inputs
> but you may need to patch code to keep vbus always on for A-device,
> it is not compliance with OTG spec.
> - Using role interface under debugfs (I move it under sysfs for v4.12).
> But you need to patch the code and let the A-device switch back to
> host after iAP is disconnected.
>
> You don't need to use above two methods together, I suggest using the
> 2nd method since OTG FSM is hard to maintain due to no mandatory use
> case for it.
>
> --
>
> Best Regards,
> Peter Chen

Thank you Peter for your response.

Yes, I will try to switch the role on disconnection of iAP device to Host. If
I understand correctly I have to do something like this -

ci_role_stop(ci); //Gadget role stop
ret = ci_role_start(ci, role); //Host role start

correct?

Regards,
Niranjan


[PATCH] chipidea: Fix issue in reconnecing gadget without insmod/rmmod

2017-04-11 Thread Niranjan Dighe
Currently usb_gadget_connect() is called only through gadget
registration via composite_driver_probe(). As a result, after a
disconnection, if the role transitions to host and back to gadget,
the gadget is not recognized by the host anymore.
This is a typical scenario with an iAP device in the following
usecase -
conn iAP dev -> send roleswitch command -> roleswitch ourself
to gadget -> disconnect iAP device -> roleswitch back to host to
enumerate the device again -> reconnect device -> resend the
roleswitch command -> roleswitch ourself to gadget -> ISSUE.

To workaround this, do the following -

1. Restart OTG FSM on SLi interrupt and on switching role to gadget
so that device transitions to B_IDLE state from B_PERIPHERAL state.
A transition from B_IDLE to B_PERIPHERAL is needed to enable
interrups and restore the correct state of the chipidea controller
so that communication with host is possible

2. usb_gadget_connect() after roleswitch to gadget so that
gadget->ops->pullup() is called and D+ line is asserted. This
causes host to "see" the device and enumeration can happen.

Signed-off-by: Niranjan Dighe <niranjan.di...@gmail.com>
---
 drivers/usb/chipidea/debug.c | 10 +-
 drivers/usb/chipidea/udc.c   |  3 +++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/chipidea/debug.c b/drivers/usb/chipidea/debug.c
index a4f7db2..66c1485 100644
--- a/drivers/usb/chipidea/debug.c
+++ b/drivers/usb/chipidea/debug.c
@@ -16,7 +16,7 @@
 #include "udc.h"
 #include "bits.h"
 #include "otg.h"
-
+extern void ci_hdrc_otg_fsm_restart(struct ci_hdrc *);
 /**
  * ci_device_show: prints information about device capabilities and status
  */
@@ -325,6 +325,14 @@ static ssize_t ci_role_write(struct file *file, const char 
__user *ubuf,
ci_role_stop(ci);
ret = ci_role_start(ci, role);
enable_irq(ci->irq);
+
+   /* REVISIT - Avoid repeated FSM restart*/
+
+   if (role == CI_ROLE_GADGET) {
+   ci_hdrc_otg_fsm_restart(ci);
+   usb_gadget_connect(>gadget);
+   }
+
pm_runtime_put_sync(ci->dev);
 
return ret ? ret : count;
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index a0accd5..1e3b827 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -29,6 +29,8 @@
 #include "otg.h"
 #include "otg_fsm.h"
 
+extern void ci_hdrc_otg_fsm_restart(struct ci_hdrc *);
+
 /* control endpoint description */
 static const struct usb_endpoint_descriptor
 ctrl_endpt_out_desc = {
@@ -1881,6 +1883,7 @@ static irqreturn_t udc_irq(struct ci_hdrc *ci)
ci->driver->suspend(>gadget);
usb_gadget_set_state(>gadget,
USB_STATE_SUSPENDED);
+   ci_hdrc_otg_fsm_restart(ci);
spin_lock(>lock);
}
}
-- 
2.1.4



[PATCH] chipidea: Fix issue in reconnecing gadget without insmod/rmmod

2017-04-11 Thread Niranjan Dighe
Currently usb_gadget_connect() is called only through gadget
registration via composite_driver_probe(). As a result, after a
disconnection, if the role transitions to host and back to gadget,
the gadget is not recognized by the host anymore.
This is a typical scenario with an iAP device in the following
usecase -
conn iAP dev -> send roleswitch command -> roleswitch ourself
to gadget -> disconnect iAP device -> roleswitch back to host to
enumerate the device again -> reconnect device -> resend the
roleswitch command -> roleswitch ourself to gadget -> ISSUE.

To workaround this, do the following -

1. Restart OTG FSM on SLi interrupt and on switching role to gadget
so that device transitions to B_IDLE state from B_PERIPHERAL state.
A transition from B_IDLE to B_PERIPHERAL is needed to enable
interrups and restore the correct state of the chipidea controller
so that communication with host is possible

2. usb_gadget_connect() after roleswitch to gadget so that
gadget->ops->pullup() is called and D+ line is asserted. This
causes host to "see" the device and enumeration can happen.

Signed-off-by: Niranjan Dighe 
---
 drivers/usb/chipidea/debug.c | 10 +-
 drivers/usb/chipidea/udc.c   |  3 +++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/chipidea/debug.c b/drivers/usb/chipidea/debug.c
index a4f7db2..66c1485 100644
--- a/drivers/usb/chipidea/debug.c
+++ b/drivers/usb/chipidea/debug.c
@@ -16,7 +16,7 @@
 #include "udc.h"
 #include "bits.h"
 #include "otg.h"
-
+extern void ci_hdrc_otg_fsm_restart(struct ci_hdrc *);
 /**
  * ci_device_show: prints information about device capabilities and status
  */
@@ -325,6 +325,14 @@ static ssize_t ci_role_write(struct file *file, const char 
__user *ubuf,
ci_role_stop(ci);
ret = ci_role_start(ci, role);
enable_irq(ci->irq);
+
+   /* REVISIT - Avoid repeated FSM restart*/
+
+   if (role == CI_ROLE_GADGET) {
+   ci_hdrc_otg_fsm_restart(ci);
+   usb_gadget_connect(>gadget);
+   }
+
pm_runtime_put_sync(ci->dev);
 
return ret ? ret : count;
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index a0accd5..1e3b827 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -29,6 +29,8 @@
 #include "otg.h"
 #include "otg_fsm.h"
 
+extern void ci_hdrc_otg_fsm_restart(struct ci_hdrc *);
+
 /* control endpoint description */
 static const struct usb_endpoint_descriptor
 ctrl_endpt_out_desc = {
@@ -1881,6 +1883,7 @@ static irqreturn_t udc_irq(struct ci_hdrc *ci)
ci->driver->suspend(>gadget);
usb_gadget_set_state(>gadget,
USB_STATE_SUSPENDED);
+   ci_hdrc_otg_fsm_restart(ci);
spin_lock(>lock);
}
}
-- 
2.1.4



[PATCH] staging: lustre/lnet: Fix wrong typecasting warning generated by sparse

2016-02-13 Thread Niranjan Dighe
Fix the following warning generated about type casting by sparse

warning: cast removes address space of expression

The current implementation casts the structure pointers with (char *)
without __user annotation and then adds sizeof struct to it, thereby
generating the sparse warning. Fixed this by removing the unnecessary
char pointer type cast.

Signed-off-by: Niranjan Dighe 
---
 drivers/staging/lustre/lnet/selftest/console.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/lustre/lnet/selftest/console.c 
b/drivers/staging/lustre/lnet/selftest/console.c
index 366211e..bc236c9 100644
--- a/drivers/staging/lustre/lnet/selftest/console.c
+++ b/drivers/staging/lustre/lnet/selftest/console.c
@@ -1460,10 +1460,8 @@ lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
return 0;
 
sfwk_stat = (sfw_counters_t __user *)_up->rpe_payload[0];
-   srpc_stat = (srpc_counters_t __user *)
- ((char *)sfwk_stat + sizeof(*sfwk_stat));
-   lnet_stat = (lnet_counters_t __user *)
- ((char *)srpc_stat + sizeof(*srpc_stat));
+   srpc_stat = (srpc_counters_t __user *)(sfwk_stat + 1);
+   lnet_stat = (lnet_counters_t __user *)(srpc_stat + 1);
 
if (copy_to_user(sfwk_stat, >str_fw, sizeof(*sfwk_stat)) ||
copy_to_user(srpc_stat, >str_rpc, sizeof(*srpc_stat)) ||
-- 
1.9.1



Re: [PATCH] staging: lustre/lnet: Fix wrong type casting warning generated by sparse

2016-02-13 Thread Niranjan Dighe
On Sun, Feb 14, 2016 at 3:19 AM, Dan Carpenter  wrote:
> On Sat, Feb 13, 2016 at 11:34:35PM +0530, Niranjan Dighe wrote:
>> diff --git a/drivers/staging/lustre/lnet/selftest/console.c 
>> b/drivers/staging/lustre/lnet/selftest/console.c
>> index 366211e..64b6a70 100644
>> --- a/drivers/staging/lustre/lnet/selftest/console.c
>> +++ b/drivers/staging/lustre/lnet/selftest/console.c
>> @@ -1461,9 +1461,9 @@ lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
>>
>>   sfwk_stat = (sfw_counters_t __user *)_up->rpe_payload[0];
>>   srpc_stat = (srpc_counters_t __user *)
>> -   ((char *)sfwk_stat + sizeof(*sfwk_stat));
>> + ((char __user *)sfwk_stat + 
>> sizeof(*sfwk_stat));
>
> This is uglier than necessary.  Do it either like this:
>
> srpc_stat = (void __user *)sfwk_stat + sizeof(*sfwk_stat);
>
> Or probably it's actually nicer to say:
>
> srpc_stat = sfwk_stat + 1;
>
> regards,
> dan carpenter
>

Yes, thanks Dan, I will send out a new patch. Please discard this one.


[PATCH] staging: lustre/lnet: Fix wrong type casting warning generated by sparse

2016-02-13 Thread Niranjan Dighe
Fixed the following warning reported by sparse about typecasting. A
userspace pointer was being typecasted by simply (char *) which causes
sparse to give the following warning -

warning: cast removes address space of expression

Fixed it by adding __user annotation to the typecasting.

Signed-off-by: Niranjan Dighe 
---
 drivers/staging/lustre/lnet/selftest/console.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/lnet/selftest/console.c 
b/drivers/staging/lustre/lnet/selftest/console.c
index 366211e..64b6a70 100644
--- a/drivers/staging/lustre/lnet/selftest/console.c
+++ b/drivers/staging/lustre/lnet/selftest/console.c
@@ -1461,9 +1461,9 @@ lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
 
sfwk_stat = (sfw_counters_t __user *)_up->rpe_payload[0];
srpc_stat = (srpc_counters_t __user *)
- ((char *)sfwk_stat + sizeof(*sfwk_stat));
+   ((char __user *)sfwk_stat + sizeof(*sfwk_stat));
lnet_stat = (lnet_counters_t __user *)
- ((char *)srpc_stat + sizeof(*srpc_stat));
+   ((char __user *)srpc_stat + sizeof(*srpc_stat));
 
if (copy_to_user(sfwk_stat, >str_fw, sizeof(*sfwk_stat)) ||
copy_to_user(srpc_stat, >str_rpc, sizeof(*srpc_stat)) ||
-- 
1.9.1



[PATCH] staging: lustre/lnet: Fix wrong type casting warning generated by sparse

2016-02-13 Thread Niranjan Dighe
Fixed the following warning reported by sparse about typecasting. A
userspace pointer was being typecasted by simply (char *) which causes
sparse to give the following warning -

warning: cast removes address space of expression

Fixed it by adding __user annotation to the typecasting.

Signed-off-by: Niranjan Dighe <niranjan.di...@gmail.com>
---
 drivers/staging/lustre/lnet/selftest/console.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/lnet/selftest/console.c 
b/drivers/staging/lustre/lnet/selftest/console.c
index 366211e..64b6a70 100644
--- a/drivers/staging/lustre/lnet/selftest/console.c
+++ b/drivers/staging/lustre/lnet/selftest/console.c
@@ -1461,9 +1461,9 @@ lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
 
sfwk_stat = (sfw_counters_t __user *)_up->rpe_payload[0];
srpc_stat = (srpc_counters_t __user *)
- ((char *)sfwk_stat + sizeof(*sfwk_stat));
+   ((char __user *)sfwk_stat + sizeof(*sfwk_stat));
lnet_stat = (lnet_counters_t __user *)
- ((char *)srpc_stat + sizeof(*srpc_stat));
+   ((char __user *)srpc_stat + sizeof(*srpc_stat));
 
if (copy_to_user(sfwk_stat, >str_fw, sizeof(*sfwk_stat)) ||
copy_to_user(srpc_stat, >str_rpc, sizeof(*srpc_stat)) ||
-- 
1.9.1



[PATCH] staging: lustre/lnet: Fix wrong typecasting warning generated by sparse

2016-02-13 Thread Niranjan Dighe
Fix the following warning generated about type casting by sparse

warning: cast removes address space of expression

The current implementation casts the structure pointers with (char *)
without __user annotation and then adds sizeof struct to it, thereby
generating the sparse warning. Fixed this by removing the unnecessary
char pointer type cast.

Signed-off-by: Niranjan Dighe <niranjan.di...@gmail.com>
---
 drivers/staging/lustre/lnet/selftest/console.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/lustre/lnet/selftest/console.c 
b/drivers/staging/lustre/lnet/selftest/console.c
index 366211e..bc236c9 100644
--- a/drivers/staging/lustre/lnet/selftest/console.c
+++ b/drivers/staging/lustre/lnet/selftest/console.c
@@ -1460,10 +1460,8 @@ lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
return 0;
 
sfwk_stat = (sfw_counters_t __user *)_up->rpe_payload[0];
-   srpc_stat = (srpc_counters_t __user *)
- ((char *)sfwk_stat + sizeof(*sfwk_stat));
-   lnet_stat = (lnet_counters_t __user *)
- ((char *)srpc_stat + sizeof(*srpc_stat));
+   srpc_stat = (srpc_counters_t __user *)(sfwk_stat + 1);
+   lnet_stat = (lnet_counters_t __user *)(srpc_stat + 1);
 
if (copy_to_user(sfwk_stat, >str_fw, sizeof(*sfwk_stat)) ||
copy_to_user(srpc_stat, >str_rpc, sizeof(*srpc_stat)) ||
-- 
1.9.1



Re: [PATCH] staging: lustre/lnet: Fix wrong type casting warning generated by sparse

2016-02-13 Thread Niranjan Dighe
On Sun, Feb 14, 2016 at 3:19 AM, Dan Carpenter <dan.carpen...@oracle.com> wrote:
> On Sat, Feb 13, 2016 at 11:34:35PM +0530, Niranjan Dighe wrote:
>> diff --git a/drivers/staging/lustre/lnet/selftest/console.c 
>> b/drivers/staging/lustre/lnet/selftest/console.c
>> index 366211e..64b6a70 100644
>> --- a/drivers/staging/lustre/lnet/selftest/console.c
>> +++ b/drivers/staging/lustre/lnet/selftest/console.c
>> @@ -1461,9 +1461,9 @@ lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
>>
>>   sfwk_stat = (sfw_counters_t __user *)_up->rpe_payload[0];
>>   srpc_stat = (srpc_counters_t __user *)
>> -   ((char *)sfwk_stat + sizeof(*sfwk_stat));
>> + ((char __user *)sfwk_stat + 
>> sizeof(*sfwk_stat));
>
> This is uglier than necessary.  Do it either like this:
>
> srpc_stat = (void __user *)sfwk_stat + sizeof(*sfwk_stat);
>
> Or probably it's actually nicer to say:
>
> srpc_stat = sfwk_stat + 1;
>
> regards,
> dan carpenter
>

Yes, thanks Dan, I will send out a new patch. Please discard this one.


Re: [PATCH] staging: lustre: Fix 'unexpected unlock' warning generated by sparse

2016-02-07 Thread Niranjan Dighe
On Thu, Feb 4, 2016 at 3:53 AM, Greg Kroah-Hartman
 wrote:
> On Sun, Jan 03, 2016 at 08:27:04AM +0530, Niranjan Dighe wrote:
>> Added annotation '__must_hold' to function ksocknal_send_keepalive_locked
>> which unlocks the lock ksocknal_data.ksnd_global_lock. As this lock is
>> not acquired in the current function, sparse warns about context imbalance
>>
>> Signed-off-by: Niranjan Dighe 
>> ---
>>  drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 1 +
>>  1 file changed, 1 insertion(+)
>
> Doesn't apply to my tree :(

Sorry about this Greg, I will recreate it on the latest staging-next and resend.

Thanks,
Niranjan Dighe


Re: [PATCH] staging: lustre: Fix 'unexpected unlock' warning generated by sparse

2016-02-07 Thread Niranjan Dighe
On Thu, Feb 4, 2016 at 3:53 AM, Greg Kroah-Hartman
<gre...@linuxfoundation.org> wrote:
> On Sun, Jan 03, 2016 at 08:27:04AM +0530, Niranjan Dighe wrote:
>> Added annotation '__must_hold' to function ksocknal_send_keepalive_locked
>> which unlocks the lock ksocknal_data.ksnd_global_lock. As this lock is
>> not acquired in the current function, sparse warns about context imbalance
>>
>> Signed-off-by: Niranjan Dighe <niranjan.di...@gmail.com>
>> ---
>>  drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 1 +
>>  1 file changed, 1 insertion(+)
>
> Doesn't apply to my tree :(

Sorry about this Greg, I will recreate it on the latest staging-next and resend.

Thanks,
Niranjan Dighe


[PATCH] staging: lustre: Fix 'unexpected unlock' warning generated by sparse

2016-01-02 Thread Niranjan Dighe
Added annotation '__must_hold' to function ksocknal_send_keepalive_locked
which unlocks the lock ksocknal_data.ksnd_global_lock. As this lock is
not acquired in the current function, sparse warns about context imbalance

Signed-off-by: Niranjan Dighe 
---
 drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c 
b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
index 477b385..29525a0 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
@@ -2336,6 +2336,7 @@ ksocknal_flush_stale_txs(ksock_peer_t *peer)
 
 static int
 ksocknal_send_keepalive_locked(ksock_peer_t *peer)
+__must_hold(_data.ksnd_global_lock)
 {
ksock_sched_t *sched;
ksock_conn_t *conn;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] staging: lustre: Fix 'unexpected unlock' warning generated by sparse

2016-01-02 Thread Niranjan Dighe
Added annotation '__must_hold' to function ksocknal_send_keepalive_locked
which unlocks the lock ksocknal_data.ksnd_global_lock. As this lock is
not acquired in the current function, sparse warns about context imbalance

Signed-off-by: Niranjan Dighe <niranjan.di...@gmail.com>
---
 drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c 
b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
index 477b385..29525a0 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
@@ -2336,6 +2336,7 @@ ksocknal_flush_stale_txs(ksock_peer_t *peer)
 
 static int
 ksocknal_send_keepalive_locked(ksock_peer_t *peer)
+__must_hold(_data.ksnd_global_lock)
 {
ksock_sched_t *sched;
ksock_conn_t *conn;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] staging: lustre/lustre/libcfs: Fix type mismatch reported by sparse

2015-12-22 Thread Niranjan Dighe
On Wed, Dec 23, 2015 at 3:34 AM, Dilger, Andreas
 wrote:
> On 2015/12/22, 06:05, "Niranjan Dighe"  wrote:
>
>>On Tue, Dec 22, 2015 at 5:14 AM, Greg Kroah-Hartman
>> wrote:
>>> On Wed, Dec 09, 2015 at 10:38:13PM +0530, Niranjan Dighe wrote:
>>>> The third argument to function kportal_memhog_alloc is expected to
>>>> be gfp_t whereas the actual argument was unsigned int. Fix this by
>>>> explicitly typecasting to gfp_t
>>>>
>>>> Signed-off-by: Niranjan Dighe 
>>>> ---
>>>>  drivers/staging/lustre/lustre/libcfs/module.c | 2 +-
>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/staging/lustre/lustre/libcfs/module.c
>>>>b/drivers/staging/lustre/lustre/libcfs/module.c
>>>> index 96d9d46..9c79f6e 100644
>>>> --- a/drivers/staging/lustre/lustre/libcfs/module.c
>>>> +++ b/drivers/staging/lustre/lustre/libcfs/module.c
>>>> @@ -268,7 +268,7 @@ static int libcfs_ioctl_int(struct cfs_psdev_file
>>>>*pfile, unsigned long cmd,
>>>>   /* XXX The ioc_flags is not GFP flags now, need
>>>>to be fixed */
>>>>   err = kportal_memhog_alloc(pfile->private_data,
>>>>  data->ioc_count,
>>>> -data->ioc_flags);
>>>> + (__force gfp_t)data->ioc_flags);
>>>
>>> No, please fix the type to be correct properly, like the comment says
>>> needs to be done.
>>>
>>> thanks,
>>>
>>> greg k-h
>>
>>Hello Greg,
>>
>>I could see that the ioc_flags member of the struct libcfs_ioctl_data
>>is used as gfp_t only in the
>>case of the ioctl IOC_LIBCFS_MEMHOG. I can think of following ways to
>>correct it -
>>
>>1. Create a union that has 2 different types encapsulated, something like
>>this -
>>union {
>>__u32 ioc_flags;
>>gfp_t alloc_flags;
>>}flags;
>>Because, the ioc_flags seems to be used in different contexts at
>>different places throughout the
>>drivers/staging/lustre directory.
>>
>>2. Is it OK to hardcode the appropriate gfp_t flags for the
>>IOC_LIBCFS_MEMHOG, as the userspace
>>seems to be taking the decision about the page allocation
>>zone/strategy, is this what is intended?
>
> The memhog functionality is used to introduce memory pressure on a client
> or server during operation to test error handling as well as memory
> allocation deadlocks (e.g. GFP_KERNEL used where GFP_NOFS should be used).
> There are other ways to do this in the kernel today, so all of the memhog
> code could just be deleted I think.
>
> This looks like kportal_memhog_alloc(), kportal_memhog_free(),
> IOC_LIBCFS_MEMHOG, and struct libcfs_device_userstate could be removed.
>
>
> Cheers, Andreas
>

Thanks Andreas, I will send out a separate patch with the cleanup as
you suggested.

Regards,
Niranjan
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] staging: lustre/lustre/libcfs: Fix type mismatch reported by sparse

2015-12-22 Thread Niranjan Dighe
On Tue, Dec 22, 2015 at 5:14 AM, Greg Kroah-Hartman
 wrote:
> On Wed, Dec 09, 2015 at 10:38:13PM +0530, Niranjan Dighe wrote:
>> The third argument to function kportal_memhog_alloc is expected to
>> be gfp_t whereas the actual argument was unsigned int. Fix this by
>> explicitly typecasting to gfp_t
>>
>> Signed-off-by: Niranjan Dighe 
>> ---
>>  drivers/staging/lustre/lustre/libcfs/module.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/staging/lustre/lustre/libcfs/module.c 
>> b/drivers/staging/lustre/lustre/libcfs/module.c
>> index 96d9d46..9c79f6e 100644
>> --- a/drivers/staging/lustre/lustre/libcfs/module.c
>> +++ b/drivers/staging/lustre/lustre/libcfs/module.c
>> @@ -268,7 +268,7 @@ static int libcfs_ioctl_int(struct cfs_psdev_file 
>> *pfile, unsigned long cmd,
>>   /* XXX The ioc_flags is not GFP flags now, need to be 
>> fixed */
>>   err = kportal_memhog_alloc(pfile->private_data,
>>  data->ioc_count,
>> -data->ioc_flags);
>> + (__force gfp_t)data->ioc_flags);
>
> No, please fix the type to be correct properly, like the comment says
> needs to be done.
>
> thanks,
>
> greg k-h

Hello Greg,

I could see that the ioc_flags member of the struct libcfs_ioctl_data
is used as gfp_t only in the
case of the ioctl IOC_LIBCFS_MEMHOG. I can think of following ways to
correct it -

1. Create a union that has 2 different types encapsulated, something like this -
union {
__u32 ioc_flags;
gfp_t alloc_flags;
}flags;
Because, the ioc_flags seems to be used in different contexts at
different places throughout the
drivers/staging/lustre directory.

2. Is it OK to hardcode the appropriate gfp_t flags for the
IOC_LIBCFS_MEMHOG, as the userspace
seems to be taking the decision about the page allocation
zone/strategy, is this what is intended?


Regards,
Niranjan Dighe
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] staging: lustre/lustre/libcfs: Fix type mismatch reported by sparse

2015-12-22 Thread Niranjan Dighe
On Wed, Dec 23, 2015 at 3:34 AM, Dilger, Andreas
<andreas.dil...@intel.com> wrote:
> On 2015/12/22, 06:05, "Niranjan Dighe" <niranjan.di...@gmail.com> wrote:
>
>>On Tue, Dec 22, 2015 at 5:14 AM, Greg Kroah-Hartman
>><gre...@linuxfoundation.org> wrote:
>>> On Wed, Dec 09, 2015 at 10:38:13PM +0530, Niranjan Dighe wrote:
>>>> The third argument to function kportal_memhog_alloc is expected to
>>>> be gfp_t whereas the actual argument was unsigned int. Fix this by
>>>> explicitly typecasting to gfp_t
>>>>
>>>> Signed-off-by: Niranjan Dighe <niranjan.di...@gmail.com>
>>>> ---
>>>>  drivers/staging/lustre/lustre/libcfs/module.c | 2 +-
>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/staging/lustre/lustre/libcfs/module.c
>>>>b/drivers/staging/lustre/lustre/libcfs/module.c
>>>> index 96d9d46..9c79f6e 100644
>>>> --- a/drivers/staging/lustre/lustre/libcfs/module.c
>>>> +++ b/drivers/staging/lustre/lustre/libcfs/module.c
>>>> @@ -268,7 +268,7 @@ static int libcfs_ioctl_int(struct cfs_psdev_file
>>>>*pfile, unsigned long cmd,
>>>>   /* XXX The ioc_flags is not GFP flags now, need
>>>>to be fixed */
>>>>   err = kportal_memhog_alloc(pfile->private_data,
>>>>  data->ioc_count,
>>>> -data->ioc_flags);
>>>> + (__force gfp_t)data->ioc_flags);
>>>
>>> No, please fix the type to be correct properly, like the comment says
>>> needs to be done.
>>>
>>> thanks,
>>>
>>> greg k-h
>>
>>Hello Greg,
>>
>>I could see that the ioc_flags member of the struct libcfs_ioctl_data
>>is used as gfp_t only in the
>>case of the ioctl IOC_LIBCFS_MEMHOG. I can think of following ways to
>>correct it -
>>
>>1. Create a union that has 2 different types encapsulated, something like
>>this -
>>union {
>>__u32 ioc_flags;
>>gfp_t alloc_flags;
>>}flags;
>>Because, the ioc_flags seems to be used in different contexts at
>>different places throughout the
>>drivers/staging/lustre directory.
>>
>>2. Is it OK to hardcode the appropriate gfp_t flags for the
>>IOC_LIBCFS_MEMHOG, as the userspace
>>seems to be taking the decision about the page allocation
>>zone/strategy, is this what is intended?
>
> The memhog functionality is used to introduce memory pressure on a client
> or server during operation to test error handling as well as memory
> allocation deadlocks (e.g. GFP_KERNEL used where GFP_NOFS should be used).
> There are other ways to do this in the kernel today, so all of the memhog
> code could just be deleted I think.
>
> This looks like kportal_memhog_alloc(), kportal_memhog_free(),
> IOC_LIBCFS_MEMHOG, and struct libcfs_device_userstate could be removed.
>
>
> Cheers, Andreas
>

Thanks Andreas, I will send out a separate patch with the cleanup as
you suggested.

Regards,
Niranjan
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] staging: lustre/lustre/libcfs: Fix type mismatch reported by sparse

2015-12-22 Thread Niranjan Dighe
On Tue, Dec 22, 2015 at 5:14 AM, Greg Kroah-Hartman
<gre...@linuxfoundation.org> wrote:
> On Wed, Dec 09, 2015 at 10:38:13PM +0530, Niranjan Dighe wrote:
>> The third argument to function kportal_memhog_alloc is expected to
>> be gfp_t whereas the actual argument was unsigned int. Fix this by
>> explicitly typecasting to gfp_t
>>
>> Signed-off-by: Niranjan Dighe <niranjan.di...@gmail.com>
>> ---
>>  drivers/staging/lustre/lustre/libcfs/module.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/staging/lustre/lustre/libcfs/module.c 
>> b/drivers/staging/lustre/lustre/libcfs/module.c
>> index 96d9d46..9c79f6e 100644
>> --- a/drivers/staging/lustre/lustre/libcfs/module.c
>> +++ b/drivers/staging/lustre/lustre/libcfs/module.c
>> @@ -268,7 +268,7 @@ static int libcfs_ioctl_int(struct cfs_psdev_file 
>> *pfile, unsigned long cmd,
>>   /* XXX The ioc_flags is not GFP flags now, need to be 
>> fixed */
>>   err = kportal_memhog_alloc(pfile->private_data,
>>  data->ioc_count,
>> -data->ioc_flags);
>> + (__force gfp_t)data->ioc_flags);
>
> No, please fix the type to be correct properly, like the comment says
> needs to be done.
>
> thanks,
>
> greg k-h

Hello Greg,

I could see that the ioc_flags member of the struct libcfs_ioctl_data
is used as gfp_t only in the
case of the ioctl IOC_LIBCFS_MEMHOG. I can think of following ways to
correct it -

1. Create a union that has 2 different types encapsulated, something like this -
union {
__u32 ioc_flags;
gfp_t alloc_flags;
}flags;
Because, the ioc_flags seems to be used in different contexts at
different places throughout the
drivers/staging/lustre directory.

2. Is it OK to hardcode the appropriate gfp_t flags for the
IOC_LIBCFS_MEMHOG, as the userspace
seems to be taking the decision about the page allocation
zone/strategy, is this what is intended?


Regards,
Niranjan Dighe
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] staging: lustre/lustre/libcfs: Fix type mismatch reported by sparse

2015-12-09 Thread Niranjan Dighe
The third argument to function kportal_memhog_alloc is expected to
be gfp_t whereas the actual argument was unsigned int. Fix this by
explicitly typecasting to gfp_t

Signed-off-by: Niranjan Dighe 
---
 drivers/staging/lustre/lustre/libcfs/module.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/lustre/lustre/libcfs/module.c 
b/drivers/staging/lustre/lustre/libcfs/module.c
index 96d9d46..9c79f6e 100644
--- a/drivers/staging/lustre/lustre/libcfs/module.c
+++ b/drivers/staging/lustre/lustre/libcfs/module.c
@@ -268,7 +268,7 @@ static int libcfs_ioctl_int(struct cfs_psdev_file *pfile, 
unsigned long cmd,
/* XXX The ioc_flags is not GFP flags now, need to be 
fixed */
err = kportal_memhog_alloc(pfile->private_data,
   data->ioc_count,
-  data->ioc_flags);
+   (__force gfp_t)data->ioc_flags);
if (err != 0)
kportal_memhog_free(pfile->private_data);
}
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] staging: lustre/lustre/libcfs: Fix type mismatch reported by sparse

2015-12-09 Thread Niranjan Dighe
The third argument to function kportal_memhog_alloc is expected to
be gfp_t whereas the actual argument was unsigned int. Fix this by
explicitly typecasting to gfp_t

Signed-off-by: Niranjan Dighe <niranjan.di...@gmail.com>
---
 drivers/staging/lustre/lustre/libcfs/module.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/lustre/lustre/libcfs/module.c 
b/drivers/staging/lustre/lustre/libcfs/module.c
index 96d9d46..9c79f6e 100644
--- a/drivers/staging/lustre/lustre/libcfs/module.c
+++ b/drivers/staging/lustre/lustre/libcfs/module.c
@@ -268,7 +268,7 @@ static int libcfs_ioctl_int(struct cfs_psdev_file *pfile, 
unsigned long cmd,
/* XXX The ioc_flags is not GFP flags now, need to be 
fixed */
err = kportal_memhog_alloc(pfile->private_data,
   data->ioc_count,
-  data->ioc_flags);
+   (__force gfp_t)data->ioc_flags);
if (err != 0)
kportal_memhog_free(pfile->private_data);
}
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 2/2] Staging: slicoss: Get rid of redundant pointer variable

2015-03-26 Thread Niranjan Dighe
Replace string directly in place of format string and remove pointer
variable which was used just once.

Signed-off-by: Niranjan Dighe 

diff --git a/drivers/staging/slicoss/slicoss.c 
b/drivers/staging/slicoss/slicoss.c
index c2bda1d..f3110f7 100644
--- a/drivers/staging/slicoss/slicoss.c
+++ b/drivers/staging/slicoss/slicoss.c
@@ -98,7 +98,6 @@
 #include "slic.h"
 
 static uint slic_first_init = 1;
-static char *slic_banner = "Alacritech SLIC Technology(tm) Server and Storage 
Accelerator (Non-Accelerated)";
 
 static char *slic_proc_version = "2.0.351  2006/07/14 12:26:00";
 
@@ -3046,7 +3045,8 @@ static int slic_entry_probe(struct pci_dev *pcidev,
return err;
 
if (did_version++ == 0) {
-   dev_info(>dev, "%s\n", slic_banner);
+   dev_info(>dev,
+   "Alacritech SLIC Technology(tm) Server and Storage Accelerator 
(Non-Accelerated)\n");
dev_info(>dev, "%s\n", slic_proc_version);
}
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 1/2] Staging: slicoss: Remove redundant and disabled code block

2015-03-26 Thread Niranjan Dighe
Removing code guarded by undefined macro SLIC_TRACE_DUMP_ENABLED

Signed-off-by: Niranjan Dighe 

diff --git a/drivers/staging/slicoss/slicoss.c 
b/drivers/staging/slicoss/slicoss.c
index 3104cb0..c2bda1d 100644
--- a/drivers/staging/slicoss/slicoss.c
+++ b/drivers/staging/slicoss/slicoss.c
@@ -2553,41 +2553,6 @@ static int slic_ioctl(struct net_device *dev, struct 
ifreq *rq, int cmd)
slic_intagg_set(adapter, intagg);
return 0;
 
-#ifdef SLIC_TRACE_DUMP_ENABLED
-   case SIOCSLICTRACEDUMP:
-   {
-   u32 value;
-
-   DBG_IOCTL("slic_ioctl  SIOCSLIC_TRACE_DUMP\n");
-
-   if (copy_from_user(data, rq->ifr_data, 28)) {
-   PRINT_ERROR
-   ("slic: copy_from_user FAILED getting 
initial simba param\n");
-   return -EFAULT;
-   }
-
-   value = data[0];
-   if (tracemon_request == SLIC_DUMP_DONE) {
-   PRINT_ERROR
-   ("ATK Diagnostic Trace Dump Requested\n");
-   tracemon_request = SLIC_DUMP_REQUESTED;
-   tracemon_request_type = value;
-   tracemon_timestamp = jiffies;
-   } else if ((tracemon_request == SLIC_DUMP_REQUESTED) ||
-  (tracemon_request ==
-   SLIC_DUMP_IN_PROGRESS)) {
-   PRINT_ERROR
-   ("ATK Diagnostic Trace Dump Requested but 
already in progress... ignore\n");
-   } else {
-   PRINT_ERROR
-   ("ATK Diagnostic Trace Dump Requested\n");
-   tracemon_request = SLIC_DUMP_REQUESTED;
-   tracemon_request_type = value;
-   tracemon_timestamp = jiffies;
-   }
-   return 0;
-   }
-#endif
case SIOCETHTOOL:
if (copy_from_user(, rq->ifr_data, sizeof(ecmd)))
return -EFAULT;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 1/2] Staging: slicoss: Remove redundant and disabled code block

2015-03-26 Thread Niranjan Dighe
Removing code guarded by undefined macro SLIC_TRACE_DUMP_ENABLED

Signed-off-by: Niranjan Dighe niranjan.di...@gmail.com

diff --git a/drivers/staging/slicoss/slicoss.c 
b/drivers/staging/slicoss/slicoss.c
index 3104cb0..c2bda1d 100644
--- a/drivers/staging/slicoss/slicoss.c
+++ b/drivers/staging/slicoss/slicoss.c
@@ -2553,41 +2553,6 @@ static int slic_ioctl(struct net_device *dev, struct 
ifreq *rq, int cmd)
slic_intagg_set(adapter, intagg);
return 0;
 
-#ifdef SLIC_TRACE_DUMP_ENABLED
-   case SIOCSLICTRACEDUMP:
-   {
-   u32 value;
-
-   DBG_IOCTL(slic_ioctl  SIOCSLIC_TRACE_DUMP\n);
-
-   if (copy_from_user(data, rq-ifr_data, 28)) {
-   PRINT_ERROR
-   (slic: copy_from_user FAILED getting 
initial simba param\n);
-   return -EFAULT;
-   }
-
-   value = data[0];
-   if (tracemon_request == SLIC_DUMP_DONE) {
-   PRINT_ERROR
-   (ATK Diagnostic Trace Dump Requested\n);
-   tracemon_request = SLIC_DUMP_REQUESTED;
-   tracemon_request_type = value;
-   tracemon_timestamp = jiffies;
-   } else if ((tracemon_request == SLIC_DUMP_REQUESTED) ||
-  (tracemon_request ==
-   SLIC_DUMP_IN_PROGRESS)) {
-   PRINT_ERROR
-   (ATK Diagnostic Trace Dump Requested but 
already in progress... ignore\n);
-   } else {
-   PRINT_ERROR
-   (ATK Diagnostic Trace Dump Requested\n);
-   tracemon_request = SLIC_DUMP_REQUESTED;
-   tracemon_request_type = value;
-   tracemon_timestamp = jiffies;
-   }
-   return 0;
-   }
-#endif
case SIOCETHTOOL:
if (copy_from_user(ecmd, rq-ifr_data, sizeof(ecmd)))
return -EFAULT;
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 2/2] Staging: slicoss: Get rid of redundant pointer variable

2015-03-26 Thread Niranjan Dighe
Replace string directly in place of format string and remove pointer
variable which was used just once.

Signed-off-by: Niranjan Dighe niranjan.di...@gmail.com

diff --git a/drivers/staging/slicoss/slicoss.c 
b/drivers/staging/slicoss/slicoss.c
index c2bda1d..f3110f7 100644
--- a/drivers/staging/slicoss/slicoss.c
+++ b/drivers/staging/slicoss/slicoss.c
@@ -98,7 +98,6 @@
 #include slic.h
 
 static uint slic_first_init = 1;
-static char *slic_banner = Alacritech SLIC Technology(tm) Server and Storage 
Accelerator (Non-Accelerated);
 
 static char *slic_proc_version = 2.0.351  2006/07/14 12:26:00;
 
@@ -3046,7 +3045,8 @@ static int slic_entry_probe(struct pci_dev *pcidev,
return err;
 
if (did_version++ == 0) {
-   dev_info(pcidev-dev, %s\n, slic_banner);
+   dev_info(pcidev-dev,
+   Alacritech SLIC Technology(tm) Server and Storage Accelerator 
(Non-Accelerated)\n);
dev_info(pcidev-dev, %s\n, slic_proc_version);
}
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] Staging: slicoss: Fix checkpatch.pl issues

2015-03-24 Thread Niranjan Dighe
Removed unused block of code guarded by #ifdef SLIC_TRACE_DUMP_ENABLED
And removed redundant static char *slic_banner and replaced actual string in
place of format string.

Signed-off-by: Niranjan Dighe 

diff --git a/drivers/staging/slicoss/slicoss.c 
b/drivers/staging/slicoss/slicoss.c
index 3104cb0..f3110f7 100644
--- a/drivers/staging/slicoss/slicoss.c
+++ b/drivers/staging/slicoss/slicoss.c
@@ -98,7 +98,6 @@
 #include "slic.h"
 
 static uint slic_first_init = 1;
-static char *slic_banner = "Alacritech SLIC Technology(tm) Server and Storage 
Accelerator (Non-Accelerated)";
 
 static char *slic_proc_version = "2.0.351  2006/07/14 12:26:00";
 
@@ -2553,41 +2552,6 @@ static int slic_ioctl(struct net_device *dev, struct 
ifreq *rq, int cmd)
slic_intagg_set(adapter, intagg);
return 0;
 
-#ifdef SLIC_TRACE_DUMP_ENABLED
-   case SIOCSLICTRACEDUMP:
-   {
-   u32 value;
-
-   DBG_IOCTL("slic_ioctl  SIOCSLIC_TRACE_DUMP\n");
-
-   if (copy_from_user(data, rq->ifr_data, 28)) {
-   PRINT_ERROR
-   ("slic: copy_from_user FAILED getting 
initial simba param\n");
-   return -EFAULT;
-   }
-
-   value = data[0];
-   if (tracemon_request == SLIC_DUMP_DONE) {
-   PRINT_ERROR
-   ("ATK Diagnostic Trace Dump Requested\n");
-   tracemon_request = SLIC_DUMP_REQUESTED;
-   tracemon_request_type = value;
-   tracemon_timestamp = jiffies;
-   } else if ((tracemon_request == SLIC_DUMP_REQUESTED) ||
-  (tracemon_request ==
-   SLIC_DUMP_IN_PROGRESS)) {
-   PRINT_ERROR
-   ("ATK Diagnostic Trace Dump Requested but 
already in progress... ignore\n");
-   } else {
-   PRINT_ERROR
-   ("ATK Diagnostic Trace Dump Requested\n");
-   tracemon_request = SLIC_DUMP_REQUESTED;
-   tracemon_request_type = value;
-   tracemon_timestamp = jiffies;
-   }
-   return 0;
-   }
-#endif
case SIOCETHTOOL:
if (copy_from_user(, rq->ifr_data, sizeof(ecmd)))
return -EFAULT;
@@ -3081,7 +3045,8 @@ static int slic_entry_probe(struct pci_dev *pcidev,
return err;
 
if (did_version++ == 0) {
-   dev_info(>dev, "%s\n", slic_banner);
+   dev_info(>dev,
+   "Alacritech SLIC Technology(tm) Server and Storage Accelerator 
(Non-Accelerated)\n");
dev_info(>dev, "%s\n", slic_proc_version);
}
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] Staging: rtl8188eu: replace kzalloc and memcpy by kmemdup

2015-03-24 Thread Niranjan Dighe
This was generated by 'make coccicheck' using scripts at
scripts/coccinelle/api/memdup.cocci.

Signed-off-by: Niranjan Dighe 

diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c 
b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
index 86d955f..be9e34a 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
@@ -5431,15 +5431,14 @@ u8 set_tx_beacon_cmd(struct adapter *padapter)
goto exit;
}
 
-   ptxBeacon_parm = kzalloc(sizeof(struct wlan_bssid_ex), GFP_KERNEL);
+   ptxBeacon_parm = kmemdup(&(pmlmeinfo->network),
+   sizeof(struct wlan_bssid_ex), GFP_KERNEL);
if (ptxBeacon_parm == NULL) {
kfree(ph2c);
res = _FAIL;
goto exit;
}
 
-   memcpy(ptxBeacon_parm, &(pmlmeinfo->network), sizeof(struct 
wlan_bssid_ex));
-
len_diff = update_hidden_ssid(ptxBeacon_parm->IEs+_BEACON_IE_OFFSET_,
  
ptxBeacon_parm->IELength-_BEACON_IE_OFFSET_,
  pmlmeinfo->hidden_ssid_mode);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Staging: slicoss: Fix checkpatch.pl issues

2015-03-24 Thread Niranjan Dighe
The following files had coding style issues that I tried to address.
It was mostly about lines spanning more than 80 characters.

Signed-off-by: Niranjan Dighe 

diff --git a/drivers/staging/slicoss/slicoss.c 
b/drivers/staging/slicoss/slicoss.c
index 3104cb0..2161bdb 100644
--- a/drivers/staging/slicoss/slicoss.c
+++ b/drivers/staging/slicoss/slicoss.c
@@ -98,7 +98,8 @@
 #include "slic.h"
 
 static uint slic_first_init = 1;
-static char *slic_banner = "Alacritech SLIC Technology(tm) Server and Storage 
Accelerator (Non-Accelerated)";
+static char *slic_banner = "Alacritech SLIC Technology(tm) Server "
+   "and Storage Accelerator (Non-Accelerated)";
 
 static char *slic_proc_version = "2.0.351  2006/07/14 12:26:00";
 
@@ -755,10 +756,10 @@ static bool slic_mac_filter(struct adapter *adapter,
 
while (mcaddr) {
if (ether_addr_equal(mcaddr->address,
-ether_frame->ether_dhost)) 
{
-   adapter->rcv_multicasts++;
-   netdev->stats.multicast++;
-   return true;
+   ether_frame->ether_dhost)) {
+   adapter->rcv_multicasts++;
+   netdev->stats.multicast++;
+   return true;
}
mcaddr = mcaddr->next;
}
@@ -2561,8 +2562,9 @@ static int slic_ioctl(struct net_device *dev, struct 
ifreq *rq, int cmd)
DBG_IOCTL("slic_ioctl  SIOCSLIC_TRACE_DUMP\n");
 
if (copy_from_user(data, rq->ifr_data, 28)) {
-   PRINT_ERROR
-   ("slic: copy_from_user FAILED getting 
initial simba param\n");
+   PRINT_ERROR(
+   "slic: copy_from_user FAILED getting initial simba param\n"
+   );
return -EFAULT;
}
 
@@ -2576,8 +2578,9 @@ static int slic_ioctl(struct net_device *dev, struct 
ifreq *rq, int cmd)
} else if ((tracemon_request == SLIC_DUMP_REQUESTED) ||
   (tracemon_request ==
SLIC_DUMP_IN_PROGRESS)) {
-   PRINT_ERROR
-   ("ATK Diagnostic Trace Dump Requested but 
already in progress... ignore\n");
+   PRINT_ERROR(
+   "ATK Diagnostic Trace Dump Requested but already in progress... 
ignore\n"
+   );
} else {
PRINT_ERROR
("ATK Diagnostic Trace Dump Requested\n");
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] Staging: rtl8188eu: replace kzalloc and memcpy by kmemdup

2015-03-24 Thread Niranjan Dighe
This was generated by 'make coccicheck' using scripts at
scripts/coccinelle/api/memdup.cocci.

Signed-off-by: Niranjan Dighe niranjan.di...@gmail.com

diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c 
b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
index 86d955f..be9e34a 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
@@ -5431,15 +5431,14 @@ u8 set_tx_beacon_cmd(struct adapter *padapter)
goto exit;
}
 
-   ptxBeacon_parm = kzalloc(sizeof(struct wlan_bssid_ex), GFP_KERNEL);
+   ptxBeacon_parm = kmemdup((pmlmeinfo-network),
+   sizeof(struct wlan_bssid_ex), GFP_KERNEL);
if (ptxBeacon_parm == NULL) {
kfree(ph2c);
res = _FAIL;
goto exit;
}
 
-   memcpy(ptxBeacon_parm, (pmlmeinfo-network), sizeof(struct 
wlan_bssid_ex));
-
len_diff = update_hidden_ssid(ptxBeacon_parm-IEs+_BEACON_IE_OFFSET_,
  
ptxBeacon_parm-IELength-_BEACON_IE_OFFSET_,
  pmlmeinfo-hidden_ssid_mode);
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Staging: slicoss: Fix checkpatch.pl issues

2015-03-24 Thread Niranjan Dighe
The following files had coding style issues that I tried to address.
It was mostly about lines spanning more than 80 characters.

Signed-off-by: Niranjan Dighe niranjan.di...@gmail.com

diff --git a/drivers/staging/slicoss/slicoss.c 
b/drivers/staging/slicoss/slicoss.c
index 3104cb0..2161bdb 100644
--- a/drivers/staging/slicoss/slicoss.c
+++ b/drivers/staging/slicoss/slicoss.c
@@ -98,7 +98,8 @@
 #include slic.h
 
 static uint slic_first_init = 1;
-static char *slic_banner = Alacritech SLIC Technology(tm) Server and Storage 
Accelerator (Non-Accelerated);
+static char *slic_banner = Alacritech SLIC Technology(tm) Server 
+   and Storage Accelerator (Non-Accelerated);
 
 static char *slic_proc_version = 2.0.351  2006/07/14 12:26:00;
 
@@ -755,10 +756,10 @@ static bool slic_mac_filter(struct adapter *adapter,
 
while (mcaddr) {
if (ether_addr_equal(mcaddr-address,
-ether_frame-ether_dhost)) 
{
-   adapter-rcv_multicasts++;
-   netdev-stats.multicast++;
-   return true;
+   ether_frame-ether_dhost)) {
+   adapter-rcv_multicasts++;
+   netdev-stats.multicast++;
+   return true;
}
mcaddr = mcaddr-next;
}
@@ -2561,8 +2562,9 @@ static int slic_ioctl(struct net_device *dev, struct 
ifreq *rq, int cmd)
DBG_IOCTL(slic_ioctl  SIOCSLIC_TRACE_DUMP\n);
 
if (copy_from_user(data, rq-ifr_data, 28)) {
-   PRINT_ERROR
-   (slic: copy_from_user FAILED getting 
initial simba param\n);
+   PRINT_ERROR(
+   slic: copy_from_user FAILED getting initial simba param\n
+   );
return -EFAULT;
}
 
@@ -2576,8 +2578,9 @@ static int slic_ioctl(struct net_device *dev, struct 
ifreq *rq, int cmd)
} else if ((tracemon_request == SLIC_DUMP_REQUESTED) ||
   (tracemon_request ==
SLIC_DUMP_IN_PROGRESS)) {
-   PRINT_ERROR
-   (ATK Diagnostic Trace Dump Requested but 
already in progress... ignore\n);
+   PRINT_ERROR(
+   ATK Diagnostic Trace Dump Requested but already in progress... 
ignore\n
+   );
} else {
PRINT_ERROR
(ATK Diagnostic Trace Dump Requested\n);
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] Staging: slicoss: Fix checkpatch.pl issues

2015-03-24 Thread Niranjan Dighe
Removed unused block of code guarded by #ifdef SLIC_TRACE_DUMP_ENABLED
And removed redundant static char *slic_banner and replaced actual string in
place of format string.

Signed-off-by: Niranjan Dighe niranjan.di...@gmail.com

diff --git a/drivers/staging/slicoss/slicoss.c 
b/drivers/staging/slicoss/slicoss.c
index 3104cb0..f3110f7 100644
--- a/drivers/staging/slicoss/slicoss.c
+++ b/drivers/staging/slicoss/slicoss.c
@@ -98,7 +98,6 @@
 #include slic.h
 
 static uint slic_first_init = 1;
-static char *slic_banner = Alacritech SLIC Technology(tm) Server and Storage 
Accelerator (Non-Accelerated);
 
 static char *slic_proc_version = 2.0.351  2006/07/14 12:26:00;
 
@@ -2553,41 +2552,6 @@ static int slic_ioctl(struct net_device *dev, struct 
ifreq *rq, int cmd)
slic_intagg_set(adapter, intagg);
return 0;
 
-#ifdef SLIC_TRACE_DUMP_ENABLED
-   case SIOCSLICTRACEDUMP:
-   {
-   u32 value;
-
-   DBG_IOCTL(slic_ioctl  SIOCSLIC_TRACE_DUMP\n);
-
-   if (copy_from_user(data, rq-ifr_data, 28)) {
-   PRINT_ERROR
-   (slic: copy_from_user FAILED getting 
initial simba param\n);
-   return -EFAULT;
-   }
-
-   value = data[0];
-   if (tracemon_request == SLIC_DUMP_DONE) {
-   PRINT_ERROR
-   (ATK Diagnostic Trace Dump Requested\n);
-   tracemon_request = SLIC_DUMP_REQUESTED;
-   tracemon_request_type = value;
-   tracemon_timestamp = jiffies;
-   } else if ((tracemon_request == SLIC_DUMP_REQUESTED) ||
-  (tracemon_request ==
-   SLIC_DUMP_IN_PROGRESS)) {
-   PRINT_ERROR
-   (ATK Diagnostic Trace Dump Requested but 
already in progress... ignore\n);
-   } else {
-   PRINT_ERROR
-   (ATK Diagnostic Trace Dump Requested\n);
-   tracemon_request = SLIC_DUMP_REQUESTED;
-   tracemon_request_type = value;
-   tracemon_timestamp = jiffies;
-   }
-   return 0;
-   }
-#endif
case SIOCETHTOOL:
if (copy_from_user(ecmd, rq-ifr_data, sizeof(ecmd)))
return -EFAULT;
@@ -3081,7 +3045,8 @@ static int slic_entry_probe(struct pci_dev *pcidev,
return err;
 
if (did_version++ == 0) {
-   dev_info(pcidev-dev, %s\n, slic_banner);
+   dev_info(pcidev-dev,
+   Alacritech SLIC Technology(tm) Server and Storage Accelerator 
(Non-Accelerated)\n);
dev_info(pcidev-dev, %s\n, slic_proc_version);
}
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/