[PATCH v2] binder: allow ANDROID_BINDER_IPC_32BIT to be unselected on 32bit ARM

2017-08-23 Thread Jisheng Zhang
As noted in commit d0bdff0db809 ("staging: Fix build issues with new
binder API"), we can add back the choice for 32bit ARM "once a 64bit
__get_user_asm_* implementation is merged." Commit e38361d032f1 ("ARM:
8091/2: add get_user() support for 8 byte types") has added the
support, so it's time to allow ANDROID_BINDER_IPC_32BIT to be
unselected on 32bit ARM so that the 64bit ABI can be tested/used on
32bit systems.

This change allows running the same 32bit userspace build no matter
the kernel is 64bit or 32bit.

Signed-off-by: Jisheng Zhang 
---
 Since v1:
  - fix the commit msg 

 drivers/android/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/android/Kconfig b/drivers/android/Kconfig
index 832e885349b1..aca5dc30b97b 100644
--- a/drivers/android/Kconfig
+++ b/drivers/android/Kconfig
@@ -32,7 +32,7 @@ config ANDROID_BINDER_DEVICES
  therefore logically separated from the other devices.
 
 config ANDROID_BINDER_IPC_32BIT
-   bool
+   bool "Use old (Android 4.4 and earlier) 32-bit binder API"
depends on !64BIT && ANDROID_BINDER_IPC
default y
---help---
-- 
2.14.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] binder: let ANDROID_BINDER_IPC_32BIT be selectable on 32bit ARM

2017-08-23 Thread Jisheng Zhang
On Wed, 23 Aug 2017 13:48:47 -0500 Rob Herring wrote:

> On Tue, Aug 22, 2017 at 9:57 PM, John Stultz  wrote:
> > On Tue, Aug 22, 2017 at 7:56 PM, John Stultz  
> > wrote:  
> >> On Tue, Aug 22, 2017 at 7:34 PM, Jisheng Zhang  
> >> wrote:  
> >>> On Tue, 22 Aug 2017 18:51:08 -0700 Greg KH wrote:
> >>>  
>  On Tue, Aug 08, 2017 at 07:03:05PM +0800, Jisheng Zhang wrote:  
>  > As noted in commit d0bdff0db809 ("staging: Fix build issues with new
>  > binder API"), we can add back the choice for 32bit ARM "once a 64bit
>  > __get_user_asm_* implementation is merged." Commit e38361d032f1 ("ARM:
>  > 8091/2: add get_user() support for 8 byte types") has added the
>  > support, so it's time to let ANDROID_BINDER_IPC_32BIT be selectable on
>  > 32bit ARM  
> 
>  Ok, but:
>   
>  >
>  > Signed-off-by: Jisheng Zhang 
>  > ---
>  >  drivers/android/Kconfig | 2 +-
>  >  1 file changed, 1 insertion(+), 1 deletion(-)
>  >
>  > diff --git a/drivers/android/Kconfig b/drivers/android/Kconfig
>  > index 832e885349b1..aca5dc30b97b 100644
>  > --- a/drivers/android/Kconfig
>  > +++ b/drivers/android/Kconfig
>  > @@ -32,7 +32,7 @@ config ANDROID_BINDER_DEVICES
>  >   therefore logically separated from the other devices.
>  >
>  >  config ANDROID_BINDER_IPC_32BIT
>  > -   bool
>  > +   bool "Use old (Android 4.4 and earlier) 32-bit binder API"
>  > depends on !64BIT && ANDROID_BINDER_IPC  
> 
>  You don't actually change the depends line :(
> 
>  Please fix up, and test it, and then resend.  
> >>>
> >>> IHOM, the dependency is correct: 64bit platforms don't support
> >>> ANDROID_BINDER_IPC_32BIT. What do you think?  
> >>
> >> I think this indicates the commit message is unclear.
> >>
> >> Part of it is that the config is inverted from the description. The
> >> patch doesn't enable the 32bit legacy binder ABI on 32bit systems, it
> >> just allows the option to be unselected, so that the 64bit ABI will be
> >> used on 32bit systems.
> >>
> >> Conceptually I don't have an objection to the change (though maybe try
> >> to rework the commit message), but I don't have anything to actually
> >> test it on right now, so I'm hesitant to ack it.  
> >
> > It might also be good to add some detail as to the motivation for this
> > change? What benefit does it bring to 32bit platforms to use the newer
> > 64bit ABI?  
> 
> It allows running the same 32-bit userspace build whether the kernel
> is 64-bit or 32-bit.
> 

Oh, yes, this is a good "motivation" which can be added into the commit msg.

thanks for the inspiration.

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 2/3] staging: rtlwifi: add MAC80211 dependency

2017-08-23 Thread Greg Kroah-Hartman
On Wed, Aug 23, 2017 at 04:19:08PM -0700, Greg Kroah-Hartman wrote:
> On Wed, Aug 23, 2017 at 08:44:46AM -0700, Randy Dunlap wrote:
> > On 08/23/2017 06:22 AM, Arnd Bergmann wrote:
> > > Like the version in drivers/net/wireless, this driver requires the
> > > MAC80211 framework, otherwise we run into a link error:
> > > 
> > > ERROR: "ieee80211_rx_irqsafe" [drivers/staging/rtlwifi/r8822be.ko] 
> > > undefined!
> > > ERROR: "cfg80211_unlink_bss" [drivers/staging/rtlwifi/r8822be.ko] 
> > > undefined!
> > > ERROR: "ieee80211_beacon_get_tim" [drivers/staging/rtlwifi/r8822be.ko] 
> > > undefined!
> > > ERROR: "ieee80211_resume_disconnect" [drivers/staging/rtlwifi/r8822be.ko] 
> > > undefined!
> > > 
> > > This adds the Kconfig dependency for it.
> > 
> > Greg,
> > Please take this patch instead of my patch from yesterday.
> 
> Ick, already took that one :(

Fixed it up by hand now, all should be good.
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: lustre: obd: check for allocation failure

2017-08-23 Thread Greg Kroah-Hartman
On Wed, Aug 23, 2017 at 09:51:31AM +0300, Dan Carpenter wrote:
> lustre_cfg_new() can fail with ERR_PTR(-ENOMEM) so we should check for
> that.
> 
> Fixes: d7e09d0397e8 ("staging: add Lustre file system client support")
> Signed-off-by: Dan Carpenter 
> 
> diff --git a/drivers/staging/lustre/lustre/obdclass/obd_mount.c 
> b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
> index 8e0d4b1d86dc..7cb99f11caa0 100644
> --- a/drivers/staging/lustre/lustre/obdclass/obd_mount.c
> +++ b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
> @@ -159,6 +159,8 @@ static int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
>   lustre_cfg_bufs_set_string(, 4, s4);
>  
>   lcfg = lustre_cfg_new(cmd, );
> + if (IS_ERR(lcfg))
> + return PTR_ERR(lcfg);
>   lcfg->lcfg_nid = nid;
>   rc = class_process_config(lcfg);
>   lustre_cfg_free(lcfg);

Doesn't apply to my tree anymore :(
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v2] staging: olpc_dcon: Change fixed function names with "%s: ", __func__

2017-08-23 Thread Greg Kroah-Hartman
On Wed, Aug 23, 2017 at 03:31:46PM +0800, Shurong Zhang wrote:
> Replace hard-coded function names in strings with "%s", __func__ 
> in the olpc_dcon.c file. Issue found by checkpatch.pl.
> 
> Signed-off-by: Shurong Zhang 
> ---
>  drivers/staging/olpc_dcon/olpc_dcon.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/olpc_dcon/olpc_dcon.c 
> b/drivers/staging/olpc_dcon/olpc_dcon.c
> index f7f3a78..3a8d99f 100644
> --- a/drivers/staging/olpc_dcon/olpc_dcon.c
> +++ b/drivers/staging/olpc_dcon/olpc_dcon.c
> @@ -456,7 +456,7 @@ static ssize_t dcon_freeze_store(struct device *dev,
>   if (ret)
>   return ret;
>  
> - pr_info("dcon_freeze_store: %lu\n", output);
> + pr_info("%s: %lu\n", __func__, output);

Should just be deleted entirely, like Dan says.

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging:rtl8188eu:core Fix coding style Issues

2017-08-23 Thread Greg KH
On Wed, Aug 23, 2017 at 02:45:51PM +0530, Janani S wrote:
> This patch solves the following warning shown by the checkpatch script
> WARNING: Comparisons should place the constants on the right side of 
> the test
> 
> Signed-off-by: Janani Sankara Babu 

Your "From:" line does not match this :(

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 2/3] staging: rtlwifi: add MAC80211 dependency

2017-08-23 Thread Greg Kroah-Hartman
On Wed, Aug 23, 2017 at 08:44:46AM -0700, Randy Dunlap wrote:
> On 08/23/2017 06:22 AM, Arnd Bergmann wrote:
> > Like the version in drivers/net/wireless, this driver requires the
> > MAC80211 framework, otherwise we run into a link error:
> > 
> > ERROR: "ieee80211_rx_irqsafe" [drivers/staging/rtlwifi/r8822be.ko] 
> > undefined!
> > ERROR: "cfg80211_unlink_bss" [drivers/staging/rtlwifi/r8822be.ko] undefined!
> > ERROR: "ieee80211_beacon_get_tim" [drivers/staging/rtlwifi/r8822be.ko] 
> > undefined!
> > ERROR: "ieee80211_resume_disconnect" [drivers/staging/rtlwifi/r8822be.ko] 
> > undefined!
> > 
> > This adds the Kconfig dependency for it.
> 
> Greg,
> Please take this patch instead of my patch from yesterday.

Ick, already took that one :(

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v2 1/5] android: binder: Refactor prev and next buffer into a helper function

2017-08-23 Thread Greg Kroah-Hartman
On Wed, Aug 23, 2017 at 08:46:39AM -0700, Sherry Yang wrote:
> Use helper functions buffer_next and buffer_prev instead
> of list_entry to get the next and previous buffers.
> 
> Signed-off-by: Sherry Yang 
> ---
>  drivers/android/binder_alloc.c | 24 +++-
>  1 file changed, 15 insertions(+), 9 deletions(-)

These all have been acked by the other google/android developers, right?

thanks,

greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 2/2] staging: android: ion: Change argument to kmalloc (checkpatch)

2017-08-23 Thread Greg KH
On Wed, Aug 23, 2017 at 12:48:29PM -0400, Nick Fox wrote:
> Apologies for the spam, but I think my last reply got rejected by Google for
> some reason and didn't get delivered to the linux-kernel mailing list. My
> original reply is below:

You can not send html email to vger.kernel.org, it will be rejected,
please fix up your email client.  Also please do not top-post on mailing
lists:

A: http://en.wikipedia.org/wiki/Top_post
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

A: No.
Q: Should I include quotations after my reply?

http://daringfireball.net/2007/07/on_top

> "Sorry about that--I'm brand new to contributing and got mixed up about which
> tree to use. Just so I'm understanding correctly, https://git.kernel.org/pub/
> scm/linux/kernel/git/next/linux-next.git/ is the tree I should be using to 
> work
> on staging drivers?

It is the tree you should be using to do any new kernel development on,
but if you specifically want to work on staging drivers, the staging.git
tree on git.kernel.org is the place to work off of, specifically the
staging-next branch there.

hope this helps,

greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] Staging: comedi: comedi_fops: fix dev_err() warning style

2017-08-23 Thread Bryan Garza
Changed dev_err() call to use function name constant instead of hardcoded
string. Issue found by checkpatch.

Signed-off-by: Bryan Garza 
---
 drivers/staging/comedi/comedi_fops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/comedi_fops.c 
b/drivers/staging/comedi/comedi_fops.c
index 34ca7823255d..e19e395b0e44 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -745,7 +745,7 @@ static void do_become_nonbusy(struct comedi_device *dev,
wake_up_interruptible_all(>wait_head);
} else {
dev_err(dev->class_dev,
-   "BUG: (?) do_become_nonbusy called with async=NULL\n");
+   "BUG: (?) %s called with async=NULL\n", __func__);
s->busy = NULL;
}
 }
--
2.14.1
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] binder: let ANDROID_BINDER_IPC_32BIT be selectable on 32bit ARM

2017-08-23 Thread Rob Herring
On Tue, Aug 22, 2017 at 9:57 PM, John Stultz  wrote:
> On Tue, Aug 22, 2017 at 7:56 PM, John Stultz  wrote:
>> On Tue, Aug 22, 2017 at 7:34 PM, Jisheng Zhang  wrote:
>>> On Tue, 22 Aug 2017 18:51:08 -0700 Greg KH wrote:
>>>
 On Tue, Aug 08, 2017 at 07:03:05PM +0800, Jisheng Zhang wrote:
 > As noted in commit d0bdff0db809 ("staging: Fix build issues with new
 > binder API"), we can add back the choice for 32bit ARM "once a 64bit
 > __get_user_asm_* implementation is merged." Commit e38361d032f1 ("ARM:
 > 8091/2: add get_user() support for 8 byte types") has added the
 > support, so it's time to let ANDROID_BINDER_IPC_32BIT be selectable on
 > 32bit ARM

 Ok, but:

 >
 > Signed-off-by: Jisheng Zhang 
 > ---
 >  drivers/android/Kconfig | 2 +-
 >  1 file changed, 1 insertion(+), 1 deletion(-)
 >
 > diff --git a/drivers/android/Kconfig b/drivers/android/Kconfig
 > index 832e885349b1..aca5dc30b97b 100644
 > --- a/drivers/android/Kconfig
 > +++ b/drivers/android/Kconfig
 > @@ -32,7 +32,7 @@ config ANDROID_BINDER_DEVICES
 >   therefore logically separated from the other devices.
 >
 >  config ANDROID_BINDER_IPC_32BIT
 > -   bool
 > +   bool "Use old (Android 4.4 and earlier) 32-bit binder API"
 > depends on !64BIT && ANDROID_BINDER_IPC

 You don't actually change the depends line :(

 Please fix up, and test it, and then resend.
>>>
>>> IHOM, the dependency is correct: 64bit platforms don't support
>>> ANDROID_BINDER_IPC_32BIT. What do you think?
>>
>> I think this indicates the commit message is unclear.
>>
>> Part of it is that the config is inverted from the description. The
>> patch doesn't enable the 32bit legacy binder ABI on 32bit systems, it
>> just allows the option to be unselected, so that the 64bit ABI will be
>> used on 32bit systems.
>>
>> Conceptually I don't have an objection to the change (though maybe try
>> to rework the commit message), but I don't have anything to actually
>> test it on right now, so I'm hesitant to ack it.
>
> It might also be good to add some detail as to the motivation for this
> change? What benefit does it bring to 32bit platforms to use the newer
> 64bit ABI?

It allows running the same 32-bit userspace build whether the kernel
is 64-bit or 32-bit.

Rob
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 0/5] android: binder: move allocator metadata and add shrinker

2017-08-23 Thread Sherry Yang
This patch set moves internal kernel data in the binder driver
out of mmap regions that is readable by user space. A shrinker
is added to the driver to dynamically manage the memory used
by binder transactions and only free pages when the system is
under memory pressure. This patch set also adds tests and
refactoring in binder allocator.

  android: binder: Refactor prev and next buffer into a helper function
  android: binder: Add allocator selftest
  android: binder: Move buffer out of area shared with user space
  android: binder: Add global lru shrinker to binder
  android: binder: Add shrinker tracepoints

 drivers/android/Kconfig |  10 +
 drivers/android/Makefile|   1 +
 drivers/android/binder.c|   4 +
 drivers/android/binder_alloc.c  | 365 --
 drivers/android/binder_alloc.h  |  30 +-
 drivers/android/binder_alloc_selftest.c | 310 ++
 drivers/android/binder_trace.h  |  55 
 7 files changed, 678 insertions(+), 97 deletions(-)
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 4/5] android: binder: Add global lru shrinker to binder

2017-08-23 Thread Sherry Yang
Hold on to the pages allocated and mapped for transaction
buffers until the system is under memory pressure. When
that happens, use linux shrinker to free pages. Without
using shrinker, patch "android: binder: Move buffer out
of area shared with user space" will cause a significant
slow down for small transactions that fit into the first
page because free list buffer header used to be inlined
with buffer data.

In addition to prevent the performance regression for
small transactions, this patch improves the performance
for transactions that take up more than one page.

Modify alloc selftest to work with the shrinker change.

Test: Run memory intensive applications (Chrome and Camera)
to trigger shrinker callbacks. Binder frees memory as expected.
Test: Run binderThroughputTest with high memory pressure
option enabled.

Signed-off-by: Sherry Yang 
---
 drivers/android/binder.c|   2 +
 drivers/android/binder_alloc.c  | 172 +++-
 drivers/android/binder_alloc.h  |  23 -
 drivers/android/binder_alloc_selftest.c |  68 ++---
 4 files changed, 225 insertions(+), 40 deletions(-)

diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index b31e64c6f666..fc5a4b9f3d97 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -5243,6 +5243,8 @@ static int __init binder_init(void)
struct binder_device *device;
struct hlist_node *tmp;
 
+   binder_alloc_shrinker_init();
+
atomic_set(_transaction_log.cur, ~0U);
atomic_set(_transaction_log_failed.cur, ~0U);
 
diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index e96659215f25..11a08bf72bcc 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -27,9 +27,12 @@
 #include 
 #include 
 #include 
+#include 
 #include "binder_alloc.h"
 #include "binder_trace.h"
 
+struct list_lru binder_alloc_lru;
+
 static DEFINE_MUTEX(binder_alloc_mmap_lock);
 
 enum {
@@ -188,8 +191,9 @@ static int binder_update_page_range(struct binder_alloc 
*alloc, int allocate,
 {
void *page_addr;
unsigned long user_page_addr;
-   struct page **page;
-   struct mm_struct *mm;
+   struct binder_lru_page *page;
+   struct mm_struct *mm = NULL;
+   bool need_mm = false;
 
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
 "%d: %s pages %pK-%pK\n", alloc->pid,
@@ -200,9 +204,18 @@ static int binder_update_page_range(struct binder_alloc 
*alloc, int allocate,
 
trace_binder_update_page_range(alloc, allocate, start, end);
 
-   if (vma)
-   mm = NULL;
-   else
+   if (allocate == 0)
+   goto free_range;
+
+   for (page_addr = start; page_addr < end; page_addr += PAGE_SIZE) {
+   page = >pages[(page_addr - alloc->buffer) / PAGE_SIZE];
+   if (!page->page_ptr) {
+   need_mm = true;
+   break;
+   }
+   }
+
+   if (!vma && need_mm)
mm = get_task_mm(alloc->tsk);
 
if (mm) {
@@ -215,10 +228,7 @@ static int binder_update_page_range(struct binder_alloc 
*alloc, int allocate,
}
}
 
-   if (allocate == 0)
-   goto free_range;
-
-   if (vma == NULL) {
+   if (!vma && need_mm) {
pr_err("%d: binder_alloc_buf failed to map pages in userspace, 
no vma\n",
alloc->pid);
goto err_no_vma;
@@ -226,18 +236,33 @@ static int binder_update_page_range(struct binder_alloc 
*alloc, int allocate,
 
for (page_addr = start; page_addr < end; page_addr += PAGE_SIZE) {
int ret;
+   bool on_lru;
 
page = >pages[(page_addr - alloc->buffer) / PAGE_SIZE];
 
-   BUG_ON(*page);
-   *page = alloc_page(GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO);
-   if (*page == NULL) {
+   if (page->page_ptr) {
+   on_lru = list_lru_del(_alloc_lru, >lru);
+   WARN_ON(!on_lru);
+   continue;
+   }
+
+   if (WARN_ON(!vma))
+   goto err_page_ptr_cleared;
+
+   page->page_ptr = alloc_page(GFP_KERNEL |
+   __GFP_HIGHMEM |
+   __GFP_ZERO);
+   if (!page->page_ptr) {
pr_err("%d: binder_alloc_buf failed for page at %pK\n",
alloc->pid, page_addr);
goto err_alloc_page_failed;
}
+   page->alloc = alloc;
+   INIT_LIST_HEAD(>lru);
+
ret = map_kernel_range_noflush((unsigned long)page_addr,
-   PAGE_SIZE, PAGE_KERNEL, page);
+  PAGE_SIZE, 

[PATCH v2 5/5] android: binder: Add shrinker tracepoints

2017-08-23 Thread Sherry Yang
Add tracepoints in binder transaction allocator to
record lru hits and alloc/free page.

Signed-off-by: Sherry Yang 
---
 drivers/android/binder_alloc.c | 27 +++--
 drivers/android/binder_trace.h | 55 ++
 2 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index 11a08bf72bcc..78c42c0d62b9 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -237,18 +237,25 @@ static int binder_update_page_range(struct binder_alloc 
*alloc, int allocate,
for (page_addr = start; page_addr < end; page_addr += PAGE_SIZE) {
int ret;
bool on_lru;
+   size_t index;
 
-   page = >pages[(page_addr - alloc->buffer) / PAGE_SIZE];
+   index = (page_addr - alloc->buffer) / PAGE_SIZE;
+   page = >pages[index];
 
if (page->page_ptr) {
+   trace_binder_alloc_lru_start(alloc, index);
+
on_lru = list_lru_del(_alloc_lru, >lru);
WARN_ON(!on_lru);
+
+   trace_binder_alloc_lru_end(alloc, index);
continue;
}
 
if (WARN_ON(!vma))
goto err_page_ptr_cleared;
 
+   trace_binder_alloc_page_start(alloc, index);
page->page_ptr = alloc_page(GFP_KERNEL |
__GFP_HIGHMEM |
__GFP_ZERO);
@@ -278,6 +285,8 @@ static int binder_update_page_range(struct binder_alloc 
*alloc, int allocate,
   alloc->pid, user_page_addr);
goto err_vm_insert_page_failed;
}
+
+   trace_binder_alloc_page_end(alloc, index);
/* vm_insert_page does not seem to increment the refcount */
}
if (mm) {
@@ -290,11 +299,17 @@ static int binder_update_page_range(struct binder_alloc 
*alloc, int allocate,
for (page_addr = end - PAGE_SIZE; page_addr >= start;
 page_addr -= PAGE_SIZE) {
bool ret;
+   size_t index;
 
-   page = >pages[(page_addr - alloc->buffer) / PAGE_SIZE];
+   index = (page_addr - alloc->buffer) / PAGE_SIZE;
+   page = >pages[index];
+
+   trace_binder_free_lru_start(alloc, index);
 
ret = list_lru_add(_alloc_lru, >lru);
WARN_ON(!ret);
+
+   trace_binder_free_lru_end(alloc, index);
continue;
 
 err_vm_insert_page_failed:
@@ -888,18 +903,26 @@ enum lru_status binder_alloc_free_page(struct list_head 
*item,
if (!down_write_trylock(>mmap_sem))
goto err_down_write_mmap_sem_failed;
 
+   trace_binder_unmap_user_start(alloc, index);
+
zap_page_range(alloc->vma,
   page_addr + alloc->user_buffer_offset,
   PAGE_SIZE);
 
+   trace_binder_unmap_user_end(alloc, index);
+
up_write(>mmap_sem);
mmput(mm);
}
 
+   trace_binder_unmap_kernel_start(alloc, index);
+
unmap_kernel_range(page_addr, PAGE_SIZE);
__free_page(page->page_ptr);
page->page_ptr = NULL;
 
+   trace_binder_unmap_kernel_end(alloc, index);
+
list_lru_isolate(lru, item);
 
mutex_unlock(>mutex);
diff --git a/drivers/android/binder_trace.h b/drivers/android/binder_trace.h
index 7967db16ba5a..76e3b9c8a8a2 100644
--- a/drivers/android/binder_trace.h
+++ b/drivers/android/binder_trace.h
@@ -291,6 +291,61 @@ TRACE_EVENT(binder_update_page_range,
  __entry->offset, __entry->size)
 );
 
+DECLARE_EVENT_CLASS(binder_lru_page_class,
+   TP_PROTO(const struct binder_alloc *alloc, size_t page_index),
+   TP_ARGS(alloc, page_index),
+   TP_STRUCT__entry(
+   __field(int, proc)
+   __field(size_t, page_index)
+   ),
+   TP_fast_assign(
+   __entry->proc = alloc->pid;
+   __entry->page_index = page_index;
+   ),
+   TP_printk("proc=%d page_index=%zu",
+ __entry->proc, __entry->page_index)
+);
+
+DEFINE_EVENT(binder_lru_page_class, binder_alloc_lru_start,
+   TP_PROTO(const struct binder_alloc *alloc, size_t page_index),
+   TP_ARGS(alloc, page_index));
+
+DEFINE_EVENT(binder_lru_page_class, binder_alloc_lru_end,
+   TP_PROTO(const struct binder_alloc *alloc, size_t page_index),
+   TP_ARGS(alloc, page_index));
+
+DEFINE_EVENT(binder_lru_page_class, binder_free_lru_start,
+   TP_PROTO(const struct binder_alloc *alloc, size_t page_index),
+   TP_ARGS(alloc, page_index));
+
+DEFINE_EVENT(binder_lru_page_class, binder_free_lru_end,
+   TP_PROTO(const struct binder_alloc 

[PATCH v2 3/5] android: binder: Move buffer out of area shared with user space

2017-08-23 Thread Sherry Yang
Binder driver allocates buffer meta data in a region that is mapped
in user space. These meta data contain pointers in the kernel.

This patch allocates buffer meta data on the kernel heap that is
not mapped in user space, and uses a pointer to refer to the data mapped.

Signed-off-by: Sherry Yang 
---
 drivers/android/binder_alloc.c  | 144 +++-
 drivers/android/binder_alloc.h  |   2 +-
 drivers/android/binder_alloc_selftest.c |  11 ++-
 3 files changed, 90 insertions(+), 67 deletions(-)

diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index f15af2b55a62..e96659215f25 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -62,9 +62,9 @@ static size_t binder_alloc_buffer_size(struct binder_alloc 
*alloc,
   struct binder_buffer *buffer)
 {
if (list_is_last(>entry, >buffers))
-   return alloc->buffer +
-  alloc->buffer_size - (void *)buffer->data;
-   return (size_t)binder_buffer_next(buffer) - (size_t)buffer->data;
+   return (u8 *)alloc->buffer +
+   alloc->buffer_size - (u8 *)buffer->data;
+   return (u8 *)binder_buffer_next(buffer)->data - (u8 *)buffer->data;
 }
 
 static void binder_insert_free_buffer(struct binder_alloc *alloc,
@@ -114,9 +114,9 @@ static void binder_insert_allocated_buffer_locked(
buffer = rb_entry(parent, struct binder_buffer, rb_node);
BUG_ON(buffer->free);
 
-   if (new_buffer < buffer)
+   if (new_buffer->data < buffer->data)
p = >rb_left;
-   else if (new_buffer > buffer)
+   else if (new_buffer->data > buffer->data)
p = >rb_right;
else
BUG();
@@ -131,18 +131,17 @@ static struct binder_buffer 
*binder_alloc_prepare_to_free_locked(
 {
struct rb_node *n = alloc->allocated_buffers.rb_node;
struct binder_buffer *buffer;
-   struct binder_buffer *kern_ptr;
+   void *kern_ptr;
 
-   kern_ptr = (struct binder_buffer *)(user_ptr - alloc->user_buffer_offset
-   - offsetof(struct binder_buffer, data));
+   kern_ptr = (void *)(user_ptr - alloc->user_buffer_offset);
 
while (n) {
buffer = rb_entry(n, struct binder_buffer, rb_node);
BUG_ON(buffer->free);
 
-   if (kern_ptr < buffer)
+   if (kern_ptr < buffer->data)
n = n->rb_left;
-   else if (kern_ptr > buffer)
+   else if (kern_ptr > buffer->data)
n = n->rb_right;
else {
/*
@@ -330,6 +329,9 @@ struct binder_buffer *binder_alloc_new_buf_locked(struct 
binder_alloc *alloc,
return ERR_PTR(-ENOSPC);
}
 
+   /* Pad 0-size buffers so they get assigned unique addresses */
+   size = max(size, sizeof(void *));
+
while (n) {
buffer = rb_entry(n, struct binder_buffer, rb_node);
BUG_ON(!buffer->free);
@@ -389,14 +391,9 @@ struct binder_buffer *binder_alloc_new_buf_locked(struct 
binder_alloc *alloc,
 
has_page_addr =
(void *)(((uintptr_t)buffer->data + buffer_size) & PAGE_MASK);
-   if (n == NULL) {
-   if (size + sizeof(struct binder_buffer) + 4 >= buffer_size)
-   buffer_size = size; /* no room for other buffers */
-   else
-   buffer_size = size + sizeof(struct binder_buffer);
-   }
+   WARN_ON(n && buffer_size != size);
end_page_addr =
-   (void *)PAGE_ALIGN((uintptr_t)buffer->data + buffer_size);
+   (void *)PAGE_ALIGN((uintptr_t)buffer->data + size);
if (end_page_addr > has_page_addr)
end_page_addr = has_page_addr;
ret = binder_update_page_range(alloc, 1,
@@ -404,17 +401,25 @@ struct binder_buffer *binder_alloc_new_buf_locked(struct 
binder_alloc *alloc,
if (ret)
return ERR_PTR(ret);
 
-   rb_erase(best_fit, >free_buffers);
-   buffer->free = 0;
-   buffer->free_in_progress = 0;
-   binder_insert_allocated_buffer_locked(alloc, buffer);
if (buffer_size != size) {
-   struct binder_buffer *new_buffer = (void *)buffer->data + size;
+   struct binder_buffer *new_buffer;
 
+   new_buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
+   if (!new_buffer) {
+   pr_err("%s: %d failed to alloc new buffer struct\n",
+  __func__, alloc->pid);
+   goto err_alloc_buf_struct_failed;
+   }
+   new_buffer->data = (u8 *)buffer->data + size;
list_add(_buffer->entry, >entry);
new_buffer->free = 1;
   

[PATCH v2 2/5] android: binder: Add allocator selftest

2017-08-23 Thread Sherry Yang
binder_alloc_selftest tests that alloc_new_buf handles page allocation and
deallocation properly when allocate and free buffers. The test allocates 5
buffers of various sizes to cover all possible page alignment cases, and
frees the buffers using a list of exhaustive freeing order.

Test: boot the device with ANDROID_BINDER_IPC_SELFTEST config option
enabled. Allocator selftest passes.

Signed-off-by: Sherry Yang 
---
 drivers/android/Kconfig |  10 ++
 drivers/android/Makefile|   1 +
 drivers/android/binder.c|   2 +
 drivers/android/binder_alloc.h  |   5 +
 drivers/android/binder_alloc_selftest.c | 271 
 5 files changed, 289 insertions(+)
 create mode 100644 drivers/android/binder_alloc_selftest.c

diff --git a/drivers/android/Kconfig b/drivers/android/Kconfig
index 832e885349b1..0f295704abd4 100644
--- a/drivers/android/Kconfig
+++ b/drivers/android/Kconfig
@@ -44,6 +44,16 @@ config ANDROID_BINDER_IPC_32BIT
 
  Note that enabling this will break newer Android user-space.
 
+config ANDROID_BINDER_IPC_SELFTEST
+   bool "Android Binder IPC Driver Selftest"
+   depends on ANDROID_BINDER_IPC
+   ---help---
+ This feature allows binder selftest to run.
+
+ Binder selftest checks the allocation and free of binder buffers
+ exhaustively with combinations of various buffer sizes and
+ alignments.
+
 endif # if ANDROID
 
 endmenu
diff --git a/drivers/android/Makefile b/drivers/android/Makefile
index 4b7c726bb560..a01254c43ee3 100644
--- a/drivers/android/Makefile
+++ b/drivers/android/Makefile
@@ -1,3 +1,4 @@
 ccflags-y += -I$(src)  # needed for trace events
 
 obj-$(CONFIG_ANDROID_BINDER_IPC)   += binder.o binder_alloc.o
+obj-$(CONFIG_ANDROID_BINDER_IPC_SELFTEST) += binder_alloc_selftest.o
diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index 9f95d7093f32..b31e64c6f666 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -4225,6 +4225,8 @@ static long binder_ioctl(struct file *filp, unsigned int 
cmd, unsigned long arg)
/*pr_info("binder_ioctl: %d:%d %x %lx\n",
proc->pid, current->pid, cmd, arg);*/
 
+   binder_selftest_alloc(>alloc);
+
trace_binder_ioctl(cmd, arg);
 
ret = wait_event_interruptible(binder_user_error_wait, 
binder_stop_on_user_error < 2);
diff --git a/drivers/android/binder_alloc.h b/drivers/android/binder_alloc.h
index 088e4ffc6230..4f02cc084c15 100644
--- a/drivers/android/binder_alloc.h
+++ b/drivers/android/binder_alloc.h
@@ -102,6 +102,11 @@ struct binder_alloc {
int pid;
 };
 
+#ifdef CONFIG_ANDROID_BINDER_IPC_SELFTEST
+void binder_selftest_alloc(struct binder_alloc *alloc);
+#else
+static inline void binder_selftest_alloc(struct binder_alloc *alloc) {}
+#endif
 extern struct binder_buffer *binder_alloc_new_buf(struct binder_alloc *alloc,
  size_t data_size,
  size_t offsets_size,
diff --git a/drivers/android/binder_alloc_selftest.c 
b/drivers/android/binder_alloc_selftest.c
new file mode 100644
index ..cc00ab6ee29d
--- /dev/null
+++ b/drivers/android/binder_alloc_selftest.c
@@ -0,0 +1,271 @@
+/* binder_alloc_selftest.c
+ *
+ * Android IPC Subsystem
+ *
+ * Copyright (C) 2017 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include 
+#include 
+#include "binder_alloc.h"
+
+#define BUFFER_NUM 5
+#define BUFFER_MIN_SIZE (PAGE_SIZE / 8)
+
+static bool binder_selftest_run = true;
+static int binder_selftest_failures;
+static DEFINE_MUTEX(binder_selftest_lock);
+
+/**
+ * enum buf_end_align_type - Page alignment of a buffer
+ * end with regard to the end of the previous buffer.
+ *
+ * In the pictures below, buf2 refers to the buffer we
+ * are aligning. buf1 refers to previous buffer by addr.
+ * Symbol [ means the start of a buffer, ] means the end
+ * of a buffer, and | means page boundaries.
+ */
+enum buf_end_align_type {
+   /**
+* @SAME_PAGE_UNALIGNED: The end of this buffer is on
+* the same page as the end of the previous buffer and
+* is not page aligned. Examples:
+* buf1 ][ buf2 ][ ...
+* buf1 ]|[ buf2 ][ ...
+*/
+   SAME_PAGE_UNALIGNED = 0,
+   /**
+* @SAME_PAGE_ALIGNED: When the end of the previous buffer
+* is not page aligned, the end of this 

[PATCH v2 1/5] android: binder: Refactor prev and next buffer into a helper function

2017-08-23 Thread Sherry Yang
Use helper functions buffer_next and buffer_prev instead
of list_entry to get the next and previous buffers.

Signed-off-by: Sherry Yang 
---
 drivers/android/binder_alloc.c | 24 +++-
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index 40f31df60580..f15af2b55a62 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -48,14 +48,23 @@ module_param_named(debug_mask, binder_alloc_debug_mask,
pr_info(x); \
} while (0)
 
+static struct binder_buffer *binder_buffer_next(struct binder_buffer *buffer)
+{
+   return list_entry(buffer->entry.next, struct binder_buffer, entry);
+}
+
+static struct binder_buffer *binder_buffer_prev(struct binder_buffer *buffer)
+{
+   return list_entry(buffer->entry.prev, struct binder_buffer, entry);
+}
+
 static size_t binder_alloc_buffer_size(struct binder_alloc *alloc,
   struct binder_buffer *buffer)
 {
if (list_is_last(>entry, >buffers))
return alloc->buffer +
   alloc->buffer_size - (void *)buffer->data;
-   return (size_t)list_entry(buffer->entry.next,
- struct binder_buffer, entry) - (size_t)buffer->data;
+   return (size_t)binder_buffer_next(buffer) - (size_t)buffer->data;
 }
 
 static void binder_insert_free_buffer(struct binder_alloc *alloc,
@@ -470,7 +479,7 @@ static void binder_delete_free_buffer(struct binder_alloc 
*alloc,
int free_page_start = 1;
 
BUG_ON(alloc->buffers.next == >entry);
-   prev = list_entry(buffer->entry.prev, struct binder_buffer, entry);
+   prev = binder_buffer_prev(buffer);
BUG_ON(!prev->free);
if (buffer_end_page(prev) == buffer_start_page(buffer)) {
free_page_start = 0;
@@ -482,8 +491,7 @@ static void binder_delete_free_buffer(struct binder_alloc 
*alloc,
}
 
if (!list_is_last(>entry, >buffers)) {
-   next = list_entry(buffer->entry.next,
- struct binder_buffer, entry);
+   next = binder_buffer_next(buffer);
if (buffer_start_page(next) == buffer_end_page(buffer)) {
free_page_end = 0;
if (buffer_start_page(next) ==
@@ -544,8 +552,7 @@ static void binder_free_buf_locked(struct binder_alloc 
*alloc,
rb_erase(>rb_node, >allocated_buffers);
buffer->free = 1;
if (!list_is_last(>entry, >buffers)) {
-   struct binder_buffer *next = list_entry(buffer->entry.next,
-   struct binder_buffer, entry);
+   struct binder_buffer *next = binder_buffer_next(buffer);
 
if (next->free) {
rb_erase(>rb_node, >free_buffers);
@@ -553,8 +560,7 @@ static void binder_free_buf_locked(struct binder_alloc 
*alloc,
}
}
if (alloc->buffers.next != >entry) {
-   struct binder_buffer *prev = list_entry(buffer->entry.prev,
-   struct binder_buffer, entry);
+   struct binder_buffer *prev = binder_buffer_prev(buffer);
 
if (prev->free) {
binder_delete_free_buffer(alloc, buffer);
-- 
2.14.1.342.g6490525c54-goog

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 2/3] staging: rtlwifi: add MAC80211 dependency

2017-08-23 Thread Randy Dunlap
On 08/23/2017 06:22 AM, Arnd Bergmann wrote:
> Like the version in drivers/net/wireless, this driver requires the
> MAC80211 framework, otherwise we run into a link error:
> 
> ERROR: "ieee80211_rx_irqsafe" [drivers/staging/rtlwifi/r8822be.ko] undefined!
> ERROR: "cfg80211_unlink_bss" [drivers/staging/rtlwifi/r8822be.ko] undefined!
> ERROR: "ieee80211_beacon_get_tim" [drivers/staging/rtlwifi/r8822be.ko] 
> undefined!
> ERROR: "ieee80211_resume_disconnect" [drivers/staging/rtlwifi/r8822be.ko] 
> undefined!
> 
> This adds the Kconfig dependency for it.

Greg,
Please take this patch instead of my patch from yesterday.

Thanks.

> Fixes: 56bde846304e ("staging: r8822be: Add existing rtlwifi and rtl_pci 
> parts for new driver")
> Signed-off-by: Arnd Bergmann 
> ---
>  drivers/staging/rtlwifi/Kconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/rtlwifi/Kconfig b/drivers/staging/rtlwifi/Kconfig
> index fc482b49f9aa..cb3a29ae764b 100644
> --- a/drivers/staging/rtlwifi/Kconfig
> +++ b/drivers/staging/rtlwifi/Kconfig
> @@ -1,6 +1,6 @@
>  config R8822BE
>   tristate "Realtek RTL8822BE Wireless Network Adapter"
> - depends on PCI && m
> + depends on PCI && MAC80211 && m
>   select FW_LOADER
>   ---help---
>   This is the staging driver for Realtek RTL8822BE 802.11ac PCIe
> 


-- 
~Randy
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] storvsc: do not assume SG list is continuous when doing bounce buffers (for 4.1 stable only)

2017-08-23 Thread Martin K. Petersen

Christoph,

> Ok.  If the stable maintainers are ok with your small fix
> I'm not going to complain too loudly.  But I'm always worried about
> stable trees divering too much from mainline.

The seemingly innocuous transition from SG_GAPS to virt boundary has
caused several data corruption regressions in the distro kernels. So has
the corresponding conversion of storvsc.

As a result, getting the current upstream code into 4.1 would mean
backporting and testing a significant amount of both block layer and
driver code. I don't think it's worth the risk. This patch is simple and
the path of least resistance.

Acked-by: Martin K. Petersen 

-- 
Martin K. Petersen  Oracle Linux Engineering
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: r8822be: fix null pointer dereference with a null driver_adapter

2017-08-23 Thread Colin King
From: Colin Ian King 

The call to _rtl_dbg_trace via macro HALMAC_RT_TRACE will trigger a null
pointer deference on the null driver_adapter.  Fix this by assigning
driver_adapter earlier to halmac_adapter->driver_adapter before the tracing
call so that a non-null driver_adapter is passed instead.

Detected by CoverityScan, CID#1454613 ("Explicit null dereferenced")

Fixes: 938a0447f094 ("staging: r8822be: Add code for halmac sub-driver")
Signed-off-by: Colin Ian King 
---
 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx.c 
b/drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx.c
index a6c8a87f755f..3a24e33228f8 100644
--- a/drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx.c
+++ b/drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx.c
@@ -4447,7 +4447,7 @@ halmac_func_p2pps_88xx(struct halmac_adapter 
*halmac_adapter,
 {
u8 h2c_buff[HALMAC_H2C_CMD_SIZE_88XX] = {0};
u16 h2c_seq_mum = 0;
-   void *driver_adapter = NULL;
+   void *driver_adapter = halmac_adapter->driver_adapter;
struct halmac_api *halmac_api;
struct halmac_h2c_header_info h2c_header_info;
enum halmac_ret_status status = HALMAC_RET_SUCCESS;
@@ -4455,7 +4455,6 @@ halmac_func_p2pps_88xx(struct halmac_adapter 
*halmac_adapter,
HALMAC_RT_TRACE(driver_adapter, HALMAC_MSG_H2C, DBG_DMESG,
"[TRACE]halmac_p2pps !!\n");
 
-   driver_adapter = halmac_adapter->driver_adapter;
halmac_api = (struct halmac_api *)halmac_adapter->halmac_api;
 
P2PPS_SET_OFFLOAD_EN(h2c_buff, p2p_ps->offload_en);
-- 
2.14.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH][next] staging: r8822be: fix memory leak of eeprom_map on error exit return

2017-08-23 Thread Colin King
From: Colin Ian King 

A memory leak of eeprom_map occurs if the call to halmac_eeprom_parser_88xx
fails. Fix this by kfree'ing it before returning.

Detected by CoverityScan, CID#1454569 ("Resource leak")
Fixes: 938a0447f094 ("staging: r8822be: Add code for halmac sub-driver")

Signed-off-by: Colin Ian King 
---
 drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx.c 
b/drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx.c
index fadb35f3ba88..a6c8a87f755f 100644
--- a/drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx.c
+++ b/drivers/staging/rtlwifi/halmac/halmac_88xx/halmac_api_88xx.c
@@ -1950,8 +1950,10 @@ halmac_dump_logical_efuse_map_88xx(struct halmac_adapter 
*halmac_adapter,
 
if (halmac_eeprom_parser_88xx(halmac_adapter,
  halmac_adapter->hal_efuse_map,
- eeprom_map) != HALMAC_RET_SUCCESS)
+ eeprom_map) != 
HALMAC_RET_SUCCESS) {
+   kfree(eeprom_map);
return HALMAC_RET_EEPROM_PARSING_FAIL;
+   }
 
PLATFORM_EVENT_INDICATION(
driver_adapter, HALMAC_FEATURE_DUMP_LOGICAL_EFUSE,
-- 
2.14.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] storvsc: do not assume SG list is continuous when doing bounce buffers (for 4.1 stable only)

2017-08-23 Thread Greg KH
On Tue, Aug 22, 2017 at 11:43:19PM -0700, Christoph Hellwig wrote:
> Ok.  If the stable maintainers are ok with your small fix
> I'm not going to complain too loudly.  But I'm always worried about
> stable trees divering too much from mainline.

Given that 90% of the time we do this, something breaks, you have a
right to be worried...
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 3/3] staging: rtlwifi: simplify logical operation

2017-08-23 Thread Arnd Bergmann
gcc notices a very complicated way to check a value
for being equal to one, and warns about it:

drivers/staging/rtlwifi/btcoexist/halbtc8822b1ant.c: In function 
'halbtc8822b1ant_set_ext_ant_switch':
drivers/staging/rtlwifi/btcoexist/halbtc8822b1ant.c:2105:9: error: '~' on a 
boolean expression [-Werror=bool-operation]
 ~switch_polatiry_inverse :
 ^
drivers/staging/rtlwifi/btcoexist/halbtc8822b1ant.c:2105:9: note: did you mean 
to use logical not?
 ~switch_polatiry_inverse :
 ^

This simplifies this expression to make it more readable
and to make gcc happy.

Fixes: 56bde846304e ("staging: r8822be: Add existing rtlwifi and rtl_pci parts 
for new driver")
Signed-off-by: Arnd Bergmann 
---
 drivers/staging/rtlwifi/btcoexist/halbtc8822b1ant.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/rtlwifi/btcoexist/halbtc8822b1ant.c 
b/drivers/staging/rtlwifi/btcoexist/halbtc8822b1ant.c
index 933d188d52b4..157395b85405 100644
--- a/drivers/staging/rtlwifi/btcoexist/halbtc8822b1ant.c
+++ b/drivers/staging/rtlwifi/btcoexist/halbtc8822b1ant.c
@@ -2101,9 +2101,7 @@ static void halbtc8822b1ant_set_ext_ant_switch(struct 
btc_coexist *btcoexist,
 * 0xcbd[1:0] = 2b'01 => Ant to BTG,
 * 0xcbd[1:0] = 2b'10 => Ant to WLG
 */
-   switch_polatiry_inverse = (rfe_type->ext_ant_switch_ctrl_polarity == 1 ?
-  ~switch_polatiry_inverse :
-  switch_polatiry_inverse);
+   switch_polatiry_inverse = rfe_type->ext_ant_switch_ctrl_polarity == 1;
 
switch (pos_type) {
default:
-- 
2.9.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/3] staging: rtlwifi: add MAC80211 dependency

2017-08-23 Thread Arnd Bergmann
Like the version in drivers/net/wireless, this driver requires the
MAC80211 framework, otherwise we run into a link error:

ERROR: "ieee80211_rx_irqsafe" [drivers/staging/rtlwifi/r8822be.ko] undefined!
ERROR: "cfg80211_unlink_bss" [drivers/staging/rtlwifi/r8822be.ko] undefined!
ERROR: "ieee80211_beacon_get_tim" [drivers/staging/rtlwifi/r8822be.ko] 
undefined!
ERROR: "ieee80211_resume_disconnect" [drivers/staging/rtlwifi/r8822be.ko] 
undefined!

This adds the Kconfig dependency for it.

Fixes: 56bde846304e ("staging: r8822be: Add existing rtlwifi and rtl_pci parts 
for new driver")
Signed-off-by: Arnd Bergmann 
---
 drivers/staging/rtlwifi/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtlwifi/Kconfig b/drivers/staging/rtlwifi/Kconfig
index fc482b49f9aa..cb3a29ae764b 100644
--- a/drivers/staging/rtlwifi/Kconfig
+++ b/drivers/staging/rtlwifi/Kconfig
@@ -1,6 +1,6 @@
 config R8822BE
tristate "Realtek RTL8822BE Wireless Network Adapter"
-   depends on PCI && m
+   depends on PCI && MAC80211 && m
select FW_LOADER
---help---
This is the staging driver for Realtek RTL8822BE 802.11ac PCIe
-- 
2.9.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v2] staging: olpc_dcon: Change fixed function names with "%s: ", __func__

2017-08-23 Thread Dan Carpenter
On Wed, Aug 23, 2017 at 03:31:46PM +0800, Shurong Zhang wrote:
> Replace hard-coded function names in strings with "%s", __func__ 
> in the olpc_dcon.c file. Issue found by checkpatch.pl.
> 
> Signed-off-by: Shurong Zhang 
> ---
>  drivers/staging/olpc_dcon/olpc_dcon.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/olpc_dcon/olpc_dcon.c 
> b/drivers/staging/olpc_dcon/olpc_dcon.c
> index f7f3a78..3a8d99f 100644
> --- a/drivers/staging/olpc_dcon/olpc_dcon.c
> +++ b/drivers/staging/olpc_dcon/olpc_dcon.c
> @@ -456,7 +456,7 @@ static ssize_t dcon_freeze_store(struct device *dev,
>   if (ret)
>   return ret;
>  
> - pr_info("dcon_freeze_store: %lu\n", output);
> + pr_info("%s: %lu\n", __func__, output);

This printk doesn't really add anything worthwhile.  Just delete it.

regards,
dan carpenter

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [BUGFIX PATCH v2] staging: ccree: save ciphertext for CTS IV

2017-08-23 Thread Stephan Mueller
Am Mittwoch, 23. August 2017, 12:47:36 CEST schrieb Gilad Ben-Yossef:

Hi Gilad,
> 
> Thank you for your persistence. It is appreciated :-)
> 
> If I understood correctly what you are referring to than the buffer is not
> allocated in this code path (unless I've missed something):

Ah, that is what I was missing :-)

Thanks for clarification. No further objections ;-)

Ciao
Stephan
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [BUGFIX PATCH v2] staging: ccree: save ciphertext for CTS IV

2017-08-23 Thread Gilad Ben-Yossef
On Wed, Aug 23, 2017 at 1:03 PM, Stephan Mueller  wrote:
> Am Mittwoch, 23. August 2017, 11:12:05 CEST schrieb Gilad Ben-Yossef:
>
> Hi Gilad,
>
>> The crypto API requires saving the last blocks of ciphertext
>> in req->info for use as IV for CTS mode. The ccree driver
>> was not doing this. This patch fixes that.
>>
>> The bug was manifested with cts(cbc(aes)) mode in tcrypt tests.
>>
>> Fixes: 302ef8ebb4b2 ("Add CryptoCell skcipher support")
>> Signed-off-by: Gilad Ben-Yossef 
>> ---
>>
>> Changes from v1:
>> - Free memory on error path, as pointed out by Stephan Mueller.
>>
>>  drivers/staging/ccree/ssi_cipher.c | 40
>> ++ 1 file changed, 36 insertions(+), 4
>> deletions(-)
>>
>> diff --git a/drivers/staging/ccree/ssi_cipher.c
>> b/drivers/staging/ccree/ssi_cipher.c index af9afea..8d31a93 100644
>> --- a/drivers/staging/ccree/ssi_cipher.c
>> +++ b/drivers/staging/ccree/ssi_cipher.c
>> @@ -24,6 +24,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>
>>  #include "ssi_config.h"
>>  #include "ssi_driver.h"
>> @@ -697,6 +698,7 @@ static int ssi_blkcipher_complete(struct device *dev,
>>  {
>>   int completion_error = 0;
>>   u32 inflight_counter;
>> + struct ablkcipher_request *req = (struct ablkcipher_request *)areq;
>>
>>   ssi_buffer_mgr_unmap_blkcipher_request(dev, req_ctx, ivsize, src, dst);
>>
>> @@ -707,6 +709,22 @@ static int ssi_blkcipher_complete(struct device *dev,
>>   ctx_p->drvdata->inflight_counter--;
>>
>>   if (areq) {
>> + /*
>> +  * The crypto API expects us to set the req->info to the last
>> +  * ciphertext block. For encrypt, simply copy from the result.
>> +  * For decrypt, we must copy from a saved buffer since this
>> +  * could be an in-place decryption operation and the src is
>> +  * lost by this point.
>> +  */
>> + if (req_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT)  
>> {
>> + memcpy(req->info, req_ctx->backup_info, ivsize);
>> + kfree(req_ctx->backup_info);
>> + } else {
>> + scatterwalk_map_and_copy(req->info, req->dst,
>> +  (req->nbytes - ivsize),
>> +  ivsize, 0);
>
> Sorry to be persistent, but what about this code path? Here you do not free
> it, yet it is allocated.

Thank you for your persistence. It is appreciated :-)

If I understood correctly what you are referring to than the buffer is not
allocated in this code path (unless I've missed something):

The buffer is allocated in ssi_ablkcipher_decrypt() which sets
req_ctx->gen_ctx.op_type
to DRV_CRYPTO_DIRECTION_DECRYPT.

The buffer is not allocated in the parallel function
(ssi_ablkcipher_encrypt) which matches
the else clause of this if statement.



>> + }
>> +
>>   ablkcipher_request_complete(areq, completion_error);
>>   return 0;
>>   }
>> @@ -739,11 +757,13 @@ static int ssi_blkcipher_process(
>>   if (unlikely(validate_data_size(ctx_p, nbytes))) {
>>   SSI_LOG_ERR("Unsupported data size %d.\n", nbytes);
>>   crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_BAD_BLOCK_LEN);
>> - return -EINVAL;
>> + rc = -EINVAL;
>> + goto exit_process;
>>   }
>>   if (nbytes == 0) {
>>   /* No data to process is valid */
>> - return 0;
>> + rc = 0;
>> + goto exit_process;
>>   }
>>   /*For CTS in case of data size aligned to 16 use CBC mode*/
>>   if (((nbytes % AES_BLOCK_SIZE) == 0) && (ctx_p->cipher_mode ==
>> DRV_CIPHER_CBC_CTS)) { @@ -818,6 +838,9 @@ static int
>> ssi_blkcipher_process(
>>   if (cts_restore_flag != 0)
>>   ctx_p->cipher_mode = DRV_CIPHER_CBC_CTS;
>>
>> + if (rc != -EINPROGRESS)
>> + kfree(req_ctx->backup_info);
>> +
>>   return rc;
>>  }
>>
>> @@ -858,7 +881,6 @@ static int ssi_ablkcipher_encrypt(struct
>> ablkcipher_request *req) struct blkcipher_req_ctx *req_ctx =
>> ablkcipher_request_ctx(req); unsigned int ivsize =
>> crypto_ablkcipher_ivsize(ablk_tfm);
>>
>> - req_ctx->backup_info = req->info;
>>   req_ctx->is_giv = false;
>>
>>   return ssi_blkcipher_process(tfm, req_ctx, req->dst, req->src,
>> req->nbytes, req->info, ivsize, (void *)req, DRV_CRYPTO_DIRECTION_ENCRYPT);
>> @@ -871,8 +893,18 @@ static int ssi_ablkcipher_decrypt(struct
>> ablkcipher_request *req) struct blkcipher_req_ctx *req_ctx =
>> ablkcipher_request_ctx(req); unsigned int ivsize =
>> crypto_ablkcipher_ivsize(ablk_tfm);
>>
>> - req_ctx->backup_info = req->info;
>> + /*
>> +  * Allocate and save the last IV sized bytes of the source, which will
>> +  * be lost in case of in-place decryption and might be needed for CTS.
>> +  

[RESEND PATCH] staging: fsl-mc: be consistent when checking strcmp() returns

2017-08-23 Thread laurentiu.tudor
From: Laurentiu Tudor 

Throughout the driver we use == 0 / != 0 to check strcmp() returns except
this place, so fix it.

Signed-off-by: Laurentiu Tudor 
---
 drivers/staging/fsl-mc/bus/dprc-driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c 
b/drivers/staging/fsl-mc/bus/dprc-driver.c
index 485abad..06df528 100644
--- a/drivers/staging/fsl-mc/bus/dprc-driver.c
+++ b/drivers/staging/fsl-mc/bus/dprc-driver.c
@@ -29,7 +29,7 @@ static bool fsl_mc_device_match(struct fsl_mc_device *mc_dev,
struct fsl_mc_obj_desc *obj_desc)
 {
return mc_dev->obj_desc.id == obj_desc->id &&
-  !strcmp(mc_dev->obj_desc.type, obj_desc->type);
+  strcmp(mc_dev->obj_desc.type, obj_desc->type) == 0;
 
 }
 
-- 
2.9.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [BUGFIX PATCH v2] staging: ccree: save ciphertext for CTS IV

2017-08-23 Thread Stephan Mueller
Am Mittwoch, 23. August 2017, 11:12:05 CEST schrieb Gilad Ben-Yossef:

Hi Gilad,

> The crypto API requires saving the last blocks of ciphertext
> in req->info for use as IV for CTS mode. The ccree driver
> was not doing this. This patch fixes that.
> 
> The bug was manifested with cts(cbc(aes)) mode in tcrypt tests.
> 
> Fixes: 302ef8ebb4b2 ("Add CryptoCell skcipher support")
> Signed-off-by: Gilad Ben-Yossef 
> ---
> 
> Changes from v1:
> - Free memory on error path, as pointed out by Stephan Mueller.
> 
>  drivers/staging/ccree/ssi_cipher.c | 40
> ++ 1 file changed, 36 insertions(+), 4
> deletions(-)
> 
> diff --git a/drivers/staging/ccree/ssi_cipher.c
> b/drivers/staging/ccree/ssi_cipher.c index af9afea..8d31a93 100644
> --- a/drivers/staging/ccree/ssi_cipher.c
> +++ b/drivers/staging/ccree/ssi_cipher.c
> @@ -24,6 +24,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
> 
>  #include "ssi_config.h"
>  #include "ssi_driver.h"
> @@ -697,6 +698,7 @@ static int ssi_blkcipher_complete(struct device *dev,
>  {
>   int completion_error = 0;
>   u32 inflight_counter;
> + struct ablkcipher_request *req = (struct ablkcipher_request *)areq;
> 
>   ssi_buffer_mgr_unmap_blkcipher_request(dev, req_ctx, ivsize, src, dst);
> 
> @@ -707,6 +709,22 @@ static int ssi_blkcipher_complete(struct device *dev,
>   ctx_p->drvdata->inflight_counter--;
> 
>   if (areq) {
> + /*
> +  * The crypto API expects us to set the req->info to the last
> +  * ciphertext block. For encrypt, simply copy from the result.
> +  * For decrypt, we must copy from a saved buffer since this
> +  * could be an in-place decryption operation and the src is
> +  * lost by this point.
> +  */
> + if (req_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT)  {
> + memcpy(req->info, req_ctx->backup_info, ivsize);
> + kfree(req_ctx->backup_info);
> + } else {
> + scatterwalk_map_and_copy(req->info, req->dst,
> +  (req->nbytes - ivsize),
> +  ivsize, 0);

Sorry to be persistent, but what about this code path? Here you do not free 
it, yet it is allocated.
> + }
> +
>   ablkcipher_request_complete(areq, completion_error);
>   return 0;
>   }
> @@ -739,11 +757,13 @@ static int ssi_blkcipher_process(
>   if (unlikely(validate_data_size(ctx_p, nbytes))) {
>   SSI_LOG_ERR("Unsupported data size %d.\n", nbytes);
>   crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_BAD_BLOCK_LEN);
> - return -EINVAL;
> + rc = -EINVAL;
> + goto exit_process;
>   }
>   if (nbytes == 0) {
>   /* No data to process is valid */
> - return 0;
> + rc = 0;
> + goto exit_process;
>   }
>   /*For CTS in case of data size aligned to 16 use CBC mode*/
>   if (((nbytes % AES_BLOCK_SIZE) == 0) && (ctx_p->cipher_mode ==
> DRV_CIPHER_CBC_CTS)) { @@ -818,6 +838,9 @@ static int
> ssi_blkcipher_process(
>   if (cts_restore_flag != 0)
>   ctx_p->cipher_mode = DRV_CIPHER_CBC_CTS;
> 
> + if (rc != -EINPROGRESS)
> + kfree(req_ctx->backup_info);
> +
>   return rc;
>  }
> 
> @@ -858,7 +881,6 @@ static int ssi_ablkcipher_encrypt(struct
> ablkcipher_request *req) struct blkcipher_req_ctx *req_ctx =
> ablkcipher_request_ctx(req); unsigned int ivsize =
> crypto_ablkcipher_ivsize(ablk_tfm);
> 
> - req_ctx->backup_info = req->info;
>   req_ctx->is_giv = false;
> 
>   return ssi_blkcipher_process(tfm, req_ctx, req->dst, req->src,
> req->nbytes, req->info, ivsize, (void *)req, DRV_CRYPTO_DIRECTION_ENCRYPT);
> @@ -871,8 +893,18 @@ static int ssi_ablkcipher_decrypt(struct
> ablkcipher_request *req) struct blkcipher_req_ctx *req_ctx =
> ablkcipher_request_ctx(req); unsigned int ivsize =
> crypto_ablkcipher_ivsize(ablk_tfm);
> 
> - req_ctx->backup_info = req->info;
> + /*
> +  * Allocate and save the last IV sized bytes of the source, which will
> +  * be lost in case of in-place decryption and might be needed for CTS.
> +  */
> + req_ctx->backup_info = kmalloc(ivsize, GFP_KERNEL);
> + if (!req_ctx->backup_info)
> + return -ENOMEM;
> +
> + scatterwalk_map_and_copy(req_ctx->backup_info, req->src,
> +  (req->nbytes - ivsize), ivsize, 0);
>   req_ctx->is_giv = false;
> +
>   return ssi_blkcipher_process(tfm, req_ctx, req->dst, req->src,
> req->nbytes, req->info, ivsize, (void *)req, DRV_CRYPTO_DIRECTION_DECRYPT);
> }



Ciao
Stephan
___
devel mailing list
de...@linuxdriverproject.org

[PATCH] staging:rtl8188eu:core Fix coding style Issues

2017-08-23 Thread Janani S
This patch solves the following warning shown by the checkpatch script
WARNING: Comparisons should place the constants on the right side of 
the test

Signed-off-by: Janani Sankara Babu 
---
 drivers/staging/rtl8188eu/core/rtw_ioctl_set.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c 
b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
index d8d88b5..767928a 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
@@ -56,7 +56,7 @@ u8 rtw_do_join(struct adapter *padapter)
RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_, 
("rtw_do_join(): site survey if scanned_queue is empty\n."));
/*  submit site_survey_cmd */
ret = rtw_sitesurvey_cmd(padapter, 
>assoc_ssid, 1, NULL, 0);
-   if (_SUCCESS != ret) {
+   if (ret != _SUCCESS) {
pmlmepriv->to_join = false;
RT_TRACE(_module_rtl871x_ioctl_set_c_, 
_drv_err_, ("rtw_do_join(): site survey return error\n."));
}
@@ -110,7 +110,7 @@ u8 rtw_do_join(struct adapter *padapter)
if (!pmlmepriv->LinkDetectInfo.bBusyTraffic ||
pmlmepriv->to_roaming > 0) {
ret = rtw_sitesurvey_cmd(padapter, 
>assoc_ssid, 1, NULL, 0);
-   if (_SUCCESS != ret) {
+   if (ret != _SUCCESS) {
pmlmepriv->to_join = false;

RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_, ("do_join(): site survey 
return error\n."));
}
@@ -621,7 +621,7 @@ int rtw_set_country(struct adapter *adapter, const char 
*country_code)
 
DBG_88E("%s country_code:%s\n", __func__, country_code);
for (i = 0; i < ARRAY_SIZE(channel_table); i++) {
-   if (0 == strcmp(channel_table[i].name, country_code)) {
+   if (strcmp(channel_table[i].name, country_code) == 0) {
channel_plan = channel_table[i].channel_plan;
break;
}
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[BUGFIX PATCH v2] staging: ccree: save ciphertext for CTS IV

2017-08-23 Thread Gilad Ben-Yossef
The crypto API requires saving the last blocks of ciphertext
in req->info for use as IV for CTS mode. The ccree driver
was not doing this. This patch fixes that.

The bug was manifested with cts(cbc(aes)) mode in tcrypt tests.

Fixes: 302ef8ebb4b2 ("Add CryptoCell skcipher support")
Signed-off-by: Gilad Ben-Yossef 
---

Changes from v1:
- Free memory on error path, as pointed out by Stephan Mueller.

 drivers/staging/ccree/ssi_cipher.c | 40 ++
 1 file changed, 36 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/ccree/ssi_cipher.c 
b/drivers/staging/ccree/ssi_cipher.c
index af9afea..8d31a93 100644
--- a/drivers/staging/ccree/ssi_cipher.c
+++ b/drivers/staging/ccree/ssi_cipher.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "ssi_config.h"
 #include "ssi_driver.h"
@@ -697,6 +698,7 @@ static int ssi_blkcipher_complete(struct device *dev,
 {
int completion_error = 0;
u32 inflight_counter;
+   struct ablkcipher_request *req = (struct ablkcipher_request *)areq;
 
ssi_buffer_mgr_unmap_blkcipher_request(dev, req_ctx, ivsize, src, dst);
 
@@ -707,6 +709,22 @@ static int ssi_blkcipher_complete(struct device *dev,
ctx_p->drvdata->inflight_counter--;
 
if (areq) {
+   /*
+* The crypto API expects us to set the req->info to the last
+* ciphertext block. For encrypt, simply copy from the result.
+* For decrypt, we must copy from a saved buffer since this
+* could be an in-place decryption operation and the src is
+* lost by this point.
+*/
+   if (req_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT)  {
+   memcpy(req->info, req_ctx->backup_info, ivsize);
+   kfree(req_ctx->backup_info);
+   } else {
+   scatterwalk_map_and_copy(req->info, req->dst,
+(req->nbytes - ivsize),
+ivsize, 0);
+   }
+
ablkcipher_request_complete(areq, completion_error);
return 0;
}
@@ -739,11 +757,13 @@ static int ssi_blkcipher_process(
if (unlikely(validate_data_size(ctx_p, nbytes))) {
SSI_LOG_ERR("Unsupported data size %d.\n", nbytes);
crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_BAD_BLOCK_LEN);
-   return -EINVAL;
+   rc = -EINVAL;
+   goto exit_process;
}
if (nbytes == 0) {
/* No data to process is valid */
-   return 0;
+   rc = 0;
+   goto exit_process;
}
/*For CTS in case of data size aligned to 16 use CBC mode*/
if (((nbytes % AES_BLOCK_SIZE) == 0) && (ctx_p->cipher_mode == 
DRV_CIPHER_CBC_CTS)) {
@@ -818,6 +838,9 @@ static int ssi_blkcipher_process(
if (cts_restore_flag != 0)
ctx_p->cipher_mode = DRV_CIPHER_CBC_CTS;
 
+   if (rc != -EINPROGRESS)
+   kfree(req_ctx->backup_info);
+
return rc;
 }
 
@@ -858,7 +881,6 @@ static int ssi_ablkcipher_encrypt(struct ablkcipher_request 
*req)
struct blkcipher_req_ctx *req_ctx = ablkcipher_request_ctx(req);
unsigned int ivsize = crypto_ablkcipher_ivsize(ablk_tfm);
 
-   req_ctx->backup_info = req->info;
req_ctx->is_giv = false;
 
return ssi_blkcipher_process(tfm, req_ctx, req->dst, req->src, 
req->nbytes, req->info, ivsize, (void *)req, DRV_CRYPTO_DIRECTION_ENCRYPT);
@@ -871,8 +893,18 @@ static int ssi_ablkcipher_decrypt(struct 
ablkcipher_request *req)
struct blkcipher_req_ctx *req_ctx = ablkcipher_request_ctx(req);
unsigned int ivsize = crypto_ablkcipher_ivsize(ablk_tfm);
 
-   req_ctx->backup_info = req->info;
+   /*
+* Allocate and save the last IV sized bytes of the source, which will
+* be lost in case of in-place decryption and might be needed for CTS.
+*/
+   req_ctx->backup_info = kmalloc(ivsize, GFP_KERNEL);
+   if (!req_ctx->backup_info)
+   return -ENOMEM;
+
+   scatterwalk_map_and_copy(req_ctx->backup_info, req->src,
+(req->nbytes - ivsize), ivsize, 0);
req_ctx->is_giv = false;
+
return ssi_blkcipher_process(tfm, req_ctx, req->dst, req->src, 
req->nbytes, req->info, ivsize, (void *)req, DRV_CRYPTO_DIRECTION_DECRYPT);
 }
 
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [BUGFIX PATCH] staging: ccree: save ciphertext for CTS IV

2017-08-23 Thread Gilad Ben-Yossef
On Wed, Aug 23, 2017 at 10:47 AM, Stephan Mueller  wrote:
> Am Mittwoch, 23. August 2017, 09:41:11 CEST schrieb Gilad Ben-Yossef:
>
> Hi Gilad,
>
>>
>>   if (areq) {
>> + /*
>> +  * The crypto API expects us to set the req->info to the last
>> +  * ciphertext block. For encrypt, simply copy from the result.
>> +  * For decrypt, we must copy from a saved buffer since this
>> +  * could be an in-place decryption operation and the src is
>> +  * lost by this point.
>> +  */
>> + if (req_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT)  
>> {
>> + memcpy(req->info, req_ctx->backup_info, ivsize);
>> + kfree(req_ctx->backup_info);
>> + } else {
>> + scatterwalk_map_and_copy(req->info, req->dst,
>> +  (req->nbytes - ivsize),
>> +  ivsize, 0);
>> + }
>> +
>>   ablkcipher_request_complete(areq, completion_error);
>>   return 0;
>>   }
>> @@ -858,7 +876,6 @@ static int ssi_ablkcipher_encrypt(struct
>> ablkcipher_request *req) struct blkcipher_req_ctx *req_ctx =
>> ablkcipher_request_ctx(req); unsigned int ivsize =
>> crypto_ablkcipher_ivsize(ablk_tfm);
>>
>> - req_ctx->backup_info = req->info;
>>   req_ctx->is_giv = false;
>>
>>   return ssi_blkcipher_process(tfm, req_ctx, req->dst, req->src,
>> req->nbytes, req->info, ivsize, (void *)req, DRV_CRYPTO_DIRECTION_ENCRYPT);
>> @@ -871,8 +888,18 @@ static int ssi_ablkcipher_decrypt(struct
>> ablkcipher_request *req) struct blkcipher_req_ctx *req_ctx =
>> ablkcipher_request_ctx(req); unsigned int ivsize =
>> crypto_ablkcipher_ivsize(ablk_tfm);
>>
>> - req_ctx->backup_info = req->info;
>> + /*
>> +  * Allocate and save the last IV sized bytes of the source, which will
>> +  * be lost in case of in-place decryption and might be needed for CTS.
>> +  */
>> + req_ctx->backup_info = kmalloc(ivsize, GFP_KERNEL);
>> + if (!req_ctx->backup_info)
>> + return -ENOMEM;
>
> Are you sure you do not add a memleak here? You seem to unconditionally
> allocate memory but conditionally free it.

You are right. I've missed freeing the memory on error code paths.
Thank you for catching that.
The code involved is badly need of a re-write but I wanted to get the
obvious bug fixed first.
I will send a revised patch

Thanks,
Gilad




-- 
Gilad Ben-Yossef
Chief Coffee Drinker

"If you take a class in large-scale robotics, can you end up in a
situation where the homework eats your dog?"
 -- Jean-Baptiste Queru
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: fsl-mc: move bus driver out of staging

2017-08-23 Thread Laurentiu Tudor


On 08/23/2017 04:39 AM, Greg KH wrote:
> On Sat, Aug 19, 2017 at 08:18:12PM +0300, laurentiu.tu...@nxp.com wrote:
>> From: Stuart Yoder 
>>
>> Move the source files out of staging into their final locations:
>>-include files in drivers/staging/fsl-mc/include go to include/linux/fsl
>>-irq-gic-v3-its-fsl-mc-msi.c goes to drivers/irqchip
>>-source in drivers/staging/fsl-mc/bus goes to drivers/bus/fsl-mc
>>-README.txt, providing and overview of DPAA goes to
>> Documentation/dpaa2/overview.txt
>>
>> Update or delete other remaining staging files-- Makefile, Kconfig, TODO.
>> Update dpaa2_eth and dpio staging drivers.
>>
>> Signed-off-by: Stuart Yoder 
>> Signed-off-by: Laurentiu Tudor 
>> [Laurentiu: rebased, add dpaa2_eth and dpio #include updates]
>> Cc: Thomas Gleixner 
>> Cc: Jason Cooper 
>> Cc: Marc Zyngier 
>
> Really?  You all have fixed all of the previous issues found?

Well, it went through quite a few rounds of fixes and cleanups (driver 
model related + other fixes, cleanup [1], more cleanup, fixes [2], 
header file cleanup [3], compile multi-arch [4]) addressing the found 
issues.

> Is it time for another real review?  If so, please ask for it.

Yes, please review. Thanks in advance!

[1] https://lkml.org/lkml/2017/2/1/235
[2] https://www.spinics.net/lists/arm-kernel/msg586688.html
[3] https://www.spinics.net/lists/arm-kernel/msg590928.html
[4] https://lkml.org/lkml/2017/7/19/639
---
Thanks & Best Regards, Laurentiu
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: fsl-mc: move bus driver out of staging

2017-08-23 Thread Marc Zyngier
On 19/08/17 18:18, laurentiu.tu...@nxp.com wrote:
> From: Stuart Yoder 
> 
> Move the source files out of staging into their final locations:
>   -include files in drivers/staging/fsl-mc/include go to include/linux/fsl
>   -irq-gic-v3-its-fsl-mc-msi.c goes to drivers/irqchip
>   -source in drivers/staging/fsl-mc/bus goes to drivers/bus/fsl-mc
>   -README.txt, providing and overview of DPAA goes to
>Documentation/dpaa2/overview.txt
> 
> Update or delete other remaining staging files-- Makefile, Kconfig, TODO.
> Update dpaa2_eth and dpio staging drivers.
> 
> Signed-off-by: Stuart Yoder 
> Signed-off-by: Laurentiu Tudor 
> [Laurentiu: rebased, add dpaa2_eth and dpio #include updates]
> Cc: Thomas Gleixner 
> Cc: Jason Cooper 
> Cc: Marc Zyngier 

[...]

> diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
> index e88d856..4839165 100644
> --- a/drivers/irqchip/Makefile
> +++ b/drivers/irqchip/Makefile
> @@ -78,3 +78,4 @@ obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o
>  obj-$(CONFIG_ARCH_ASPEED)+= irq-aspeed-vic.o irq-aspeed-i2c-ic.o
>  obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o
>  obj-$(CONFIG_QCOM_IRQ_COMBINER)  += qcom-irq-combiner.o
> +obj-$(CONFIG_FSL_MC_BUS) += irq-gic-v3-its-fsl-mc-msi.o

Please keep the ITS bus glue next to the rest of the ITS code.

Thanks,

M.
-- 
Jazz is not dead. It just smells funny...
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [BUGFIX PATCH] staging: ccree: save ciphertext for CTS IV

2017-08-23 Thread Stephan Mueller
Am Mittwoch, 23. August 2017, 09:41:11 CEST schrieb Gilad Ben-Yossef:

Hi Gilad,

> 
>   if (areq) {
> + /*
> +  * The crypto API expects us to set the req->info to the last
> +  * ciphertext block. For encrypt, simply copy from the result.
> +  * For decrypt, we must copy from a saved buffer since this
> +  * could be an in-place decryption operation and the src is
> +  * lost by this point.
> +  */
> + if (req_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT)  {
> + memcpy(req->info, req_ctx->backup_info, ivsize);
> + kfree(req_ctx->backup_info);
> + } else {
> + scatterwalk_map_and_copy(req->info, req->dst,
> +  (req->nbytes - ivsize),
> +  ivsize, 0);
> + }
> +
>   ablkcipher_request_complete(areq, completion_error);
>   return 0;
>   }
> @@ -858,7 +876,6 @@ static int ssi_ablkcipher_encrypt(struct
> ablkcipher_request *req) struct blkcipher_req_ctx *req_ctx =
> ablkcipher_request_ctx(req); unsigned int ivsize =
> crypto_ablkcipher_ivsize(ablk_tfm);
> 
> - req_ctx->backup_info = req->info;
>   req_ctx->is_giv = false;
> 
>   return ssi_blkcipher_process(tfm, req_ctx, req->dst, req->src,
> req->nbytes, req->info, ivsize, (void *)req, DRV_CRYPTO_DIRECTION_ENCRYPT);
> @@ -871,8 +888,18 @@ static int ssi_ablkcipher_decrypt(struct
> ablkcipher_request *req) struct blkcipher_req_ctx *req_ctx =
> ablkcipher_request_ctx(req); unsigned int ivsize =
> crypto_ablkcipher_ivsize(ablk_tfm);
> 
> - req_ctx->backup_info = req->info;
> + /*
> +  * Allocate and save the last IV sized bytes of the source, which will
> +  * be lost in case of in-place decryption and might be needed for CTS.
> +  */
> + req_ctx->backup_info = kmalloc(ivsize, GFP_KERNEL);
> + if (!req_ctx->backup_info)
> + return -ENOMEM;

Are you sure you do not add a memleak here? You seem to unconditionally 
allocate memory but conditionally free it.

Ciao
Stephan
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[BUGFIX PATCH] staging: ccree: save ciphertext for CTS IV

2017-08-23 Thread Gilad Ben-Yossef
The crypto API requires saving the last blocks of ciphertext
in req->info for use as IV for CTS mode. The ccree driver
was not doing this. This patch fixes that.

The bug was manifested with cts(cbc(aes)) mode in tcrypt tests.

Fixes: 302ef8ebb4b2 ("Add CryptoCell skcipher support")
Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_cipher.c | 31 +--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/ccree/ssi_cipher.c 
b/drivers/staging/ccree/ssi_cipher.c
index af9afea..01011a2 100644
--- a/drivers/staging/ccree/ssi_cipher.c
+++ b/drivers/staging/ccree/ssi_cipher.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "ssi_config.h"
 #include "ssi_driver.h"
@@ -697,6 +698,7 @@ static int ssi_blkcipher_complete(struct device *dev,
 {
int completion_error = 0;
u32 inflight_counter;
+   struct ablkcipher_request *req = (struct ablkcipher_request *)areq;
 
ssi_buffer_mgr_unmap_blkcipher_request(dev, req_ctx, ivsize, src, dst);
 
@@ -707,6 +709,22 @@ static int ssi_blkcipher_complete(struct device *dev,
ctx_p->drvdata->inflight_counter--;
 
if (areq) {
+   /*
+* The crypto API expects us to set the req->info to the last
+* ciphertext block. For encrypt, simply copy from the result.
+* For decrypt, we must copy from a saved buffer since this
+* could be an in-place decryption operation and the src is
+* lost by this point.
+*/
+   if (req_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT)  {
+   memcpy(req->info, req_ctx->backup_info, ivsize);
+   kfree(req_ctx->backup_info);
+   } else {
+   scatterwalk_map_and_copy(req->info, req->dst,
+(req->nbytes - ivsize),
+ivsize, 0);
+   }
+
ablkcipher_request_complete(areq, completion_error);
return 0;
}
@@ -858,7 +876,6 @@ static int ssi_ablkcipher_encrypt(struct ablkcipher_request 
*req)
struct blkcipher_req_ctx *req_ctx = ablkcipher_request_ctx(req);
unsigned int ivsize = crypto_ablkcipher_ivsize(ablk_tfm);
 
-   req_ctx->backup_info = req->info;
req_ctx->is_giv = false;
 
return ssi_blkcipher_process(tfm, req_ctx, req->dst, req->src, 
req->nbytes, req->info, ivsize, (void *)req, DRV_CRYPTO_DIRECTION_ENCRYPT);
@@ -871,8 +888,18 @@ static int ssi_ablkcipher_decrypt(struct 
ablkcipher_request *req)
struct blkcipher_req_ctx *req_ctx = ablkcipher_request_ctx(req);
unsigned int ivsize = crypto_ablkcipher_ivsize(ablk_tfm);
 
-   req_ctx->backup_info = req->info;
+   /*
+* Allocate and save the last IV sized bytes of the source, which will
+* be lost in case of in-place decryption and might be needed for CTS.
+*/
+   req_ctx->backup_info = kmalloc(ivsize, GFP_KERNEL);
+   if (!req_ctx->backup_info)
+   return -ENOMEM;
+
+   scatterwalk_map_and_copy(req_ctx->backup_info, req->src,
+(req->nbytes - ivsize), ivsize, 0);
req_ctx->is_giv = false;
+
return ssi_blkcipher_process(tfm, req_ctx, req->dst, req->src, 
req->nbytes, req->info, ivsize, (void *)req, DRV_CRYPTO_DIRECTION_DECRYPT);
 }
 
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2] staging: olpc_dcon: Change fixed function names with "%s: ", __func__

2017-08-23 Thread Shurong Zhang
Replace hard-coded function names in strings with "%s", __func__ 
in the olpc_dcon.c file. Issue found by checkpatch.pl.

Signed-off-by: Shurong Zhang 
---
 drivers/staging/olpc_dcon/olpc_dcon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/olpc_dcon/olpc_dcon.c 
b/drivers/staging/olpc_dcon/olpc_dcon.c
index f7f3a78..3a8d99f 100644
--- a/drivers/staging/olpc_dcon/olpc_dcon.c
+++ b/drivers/staging/olpc_dcon/olpc_dcon.c
@@ -456,7 +456,7 @@ static ssize_t dcon_freeze_store(struct device *dev,
if (ret)
return ret;
 
-   pr_info("dcon_freeze_store: %lu\n", output);
+   pr_info("%s: %lu\n", __func__, output);
 
switch (output) {
case 0:
-- 
2.7.4



___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: lustre: obd: check for allocation failure

2017-08-23 Thread Dan Carpenter
lustre_cfg_new() can fail with ERR_PTR(-ENOMEM) so we should check for
that.

Fixes: d7e09d0397e8 ("staging: add Lustre file system client support")
Signed-off-by: Dan Carpenter 

diff --git a/drivers/staging/lustre/lustre/obdclass/obd_mount.c 
b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
index 8e0d4b1d86dc..7cb99f11caa0 100644
--- a/drivers/staging/lustre/lustre/obdclass/obd_mount.c
+++ b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
@@ -159,6 +159,8 @@ static int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
lustre_cfg_bufs_set_string(, 4, s4);
 
lcfg = lustre_cfg_new(cmd, );
+   if (IS_ERR(lcfg))
+   return PTR_ERR(lcfg);
lcfg->lcfg_nid = nid;
rc = class_process_config(lcfg);
lustre_cfg_free(lcfg);
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] storvsc: do not assume SG list is continuous when doing bounce buffers (for 4.1 stable only)

2017-08-23 Thread Christoph Hellwig
Ok.  If the stable maintainers are ok with your small fix
I'm not going to complain too loudly.  But I'm always worried about
stable trees divering too much from mainline.
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel