All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] staging: Remove set but not used variable ‘status’
@ 2019-05-25  4:26 ` Mao Wenan
  0 siblings, 0 replies; 20+ messages in thread
From: Mao Wenan @ 2019-05-25  4:26 UTC (permalink / raw)
  To: gregkh, jeremy; +Cc: devel, linux-kernel, kernel-janitors, Mao Wenan

Fixes gcc '-Wunused-but-set-variable' warning:

drivers/staging/kpc2000/kpc_spi/spi_driver.c: In function
‘kp_spi_transfer_one_message’:
drivers/staging/kpc2000/kpc_spi/spi_driver.c:282:9: warning: variable
‘status’ set but not used [-Wunused-but-set-variable]
     int status = 0;
         ^~~~~~
The variable 'status' is not used any more, remve it.

Signed-off-by: Mao Wenan <maowenan@huawei.com>
---
 drivers/staging/kpc2000/kpc_spi/spi_driver.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc_spi/spi_driver.c b/drivers/staging/kpc2000/kpc_spi/spi_driver.c
index 86df16547a92..16f9518f8d63 100644
--- a/drivers/staging/kpc2000/kpc_spi/spi_driver.c
+++ b/drivers/staging/kpc2000/kpc_spi/spi_driver.c
@@ -279,7 +279,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
     struct kp_spi       *kpspi;
     struct spi_transfer *transfer;
     union kp_spi_config sc;
-    int status = 0;
     
     spidev = m->spi;
     kpspi = spi_master_get_devdata(master);
@@ -332,7 +331,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
     /* do the transfers for this message */
     list_for_each_entry(transfer, &m->transfers, transfer_list) {
         if (transfer->tx_buf == NULL && transfer->rx_buf == NULL && transfer->len) {
-            status = -EINVAL;
             break;
         }
         
@@ -370,7 +368,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
             m->actual_length += count;
             
             if (count != transfer->len) {
-                status = -EIO;
                 break;
             }
         }
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH net] staging: Remove set but not used =?UTF-8?q?=20variable=20=E2=80=98
@ 2019-05-25  4:26 ` Mao Wenan
  0 siblings, 0 replies; 20+ messages in thread
From: Mao Wenan @ 2019-05-25  4:26 UTC (permalink / raw)
  To: gregkh, jeremy; +Cc: devel, linux-kernel, kernel-janitors, Mao Wenan

Fixes gcc '-Wunused-but-set-variable' warning:

drivers/staging/kpc2000/kpc_spi/spi_driver.c: In function
‘kp_spi_transfer_one_message’:
drivers/staging/kpc2000/kpc_spi/spi_driver.c:282:9: warning: variable
‘status’ set but not used [-Wunused-but-set-variable]
     int status = 0;
         ^~~~~~
The variable 'status' is not used any more, remve it.

Signed-off-by: Mao Wenan <maowenan@huawei.com>
---
 drivers/staging/kpc2000/kpc_spi/spi_driver.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc_spi/spi_driver.c b/drivers/staging/kpc2000/kpc_spi/spi_driver.c
index 86df16547a92..16f9518f8d63 100644
--- a/drivers/staging/kpc2000/kpc_spi/spi_driver.c
+++ b/drivers/staging/kpc2000/kpc_spi/spi_driver.c
@@ -279,7 +279,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
     struct kp_spi       *kpspi;
     struct spi_transfer *transfer;
     union kp_spi_config sc;
-    int status = 0;
     
     spidev = m->spi;
     kpspi = spi_master_get_devdata(master);
@@ -332,7 +331,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
     /* do the transfers for this message */
     list_for_each_entry(transfer, &m->transfers, transfer_list) {
         if (transfer->tx_buf = NULL && transfer->rx_buf = NULL && transfer->len) {
-            status = -EINVAL;
             break;
         }
         
@@ -370,7 +368,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
             m->actual_length += count;
             
             if (count != transfer->len) {
-                status = -EIO;
                 break;
             }
         }
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH net] staging: Remove set but not used variable ‘status’
  2019-05-25  4:26 ` [PATCH net] staging: Remove set but not used =?UTF-8?q?=20variable=20=E2=80=98 Mao Wenan
@ 2019-05-25  5:01   ` Greg KH
  -1 siblings, 0 replies; 20+ messages in thread
From: Greg KH @ 2019-05-25  5:01 UTC (permalink / raw)
  To: Mao Wenan; +Cc: jeremy, devel, kernel-janitors, linux-kernel

On Sat, May 25, 2019 at 12:26:42PM +0800, Mao Wenan wrote:
> Fixes gcc '-Wunused-but-set-variable' warning:
> 
> drivers/staging/kpc2000/kpc_spi/spi_driver.c: In function
> ‘kp_spi_transfer_one_message’:
> drivers/staging/kpc2000/kpc_spi/spi_driver.c:282:9: warning: variable
> ‘status’ set but not used [-Wunused-but-set-variable]
>      int status = 0;
>          ^~~~~~
> The variable 'status' is not used any more, remve it.
> 
> Signed-off-by: Mao Wenan <maowenan@huawei.com>
> ---
>  drivers/staging/kpc2000/kpc_spi/spi_driver.c | 3 ---
>  1 file changed, 3 deletions(-)

What is [PATCH net] in the subject for?  This is not a networking driver
:(


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH net] staging: Remove  =?utf-8?Q?set_but_not_used_variable_=E2=80=98status=E2=
@ 2019-05-25  5:01   ` Greg KH
  0 siblings, 0 replies; 20+ messages in thread
From: Greg KH @ 2019-05-25  5:01 UTC (permalink / raw)
  To: Mao Wenan; +Cc: jeremy, devel, kernel-janitors, linux-kernel

On Sat, May 25, 2019 at 12:26:42PM +0800, Mao Wenan wrote:
> Fixes gcc '-Wunused-but-set-variable' warning:
> 
> drivers/staging/kpc2000/kpc_spi/spi_driver.c: In function
> ‘kp_spi_transfer_one_message’:
> drivers/staging/kpc2000/kpc_spi/spi_driver.c:282:9: warning: variable
> ‘status’ set but not used [-Wunused-but-set-variable]
>      int status = 0;
>          ^~~~~~
> The variable 'status' is not used any more, remve it.
> 
> Signed-off-by: Mao Wenan <maowenan@huawei.com>
> ---
>  drivers/staging/kpc2000/kpc_spi/spi_driver.c | 3 ---
>  1 file changed, 3 deletions(-)

What is [PATCH net] in the subject for?  This is not a networking driver
:(

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH net] staging: Remove set but not used variable ‘status’
  2019-05-25  5:01   ` [PATCH net] staging: Remove =?utf-8?Q?set_but_not_used_variable_=E2=80=98status=E2= Greg KH
@ 2019-05-25  6:39     ` maowenan
  -1 siblings, 0 replies; 20+ messages in thread
From: maowenan @ 2019-05-25  6:39 UTC (permalink / raw)
  To: Greg KH; +Cc: jeremy, devel, kernel-janitors, linux-kernel



On 2019/5/25 13:01, Greg KH wrote:
> On Sat, May 25, 2019 at 12:26:42PM +0800, Mao Wenan wrote:
>> Fixes gcc '-Wunused-but-set-variable' warning:
>>
>> drivers/staging/kpc2000/kpc_spi/spi_driver.c: In function
>> ‘kp_spi_transfer_one_message’:
>> drivers/staging/kpc2000/kpc_spi/spi_driver.c:282:9: warning: variable
>> ‘status’ set but not used [-Wunused-but-set-variable]
>>      int status = 0;
>>          ^~~~~~
>> The variable 'status' is not used any more, remve it.
>>
>> Signed-off-by: Mao Wenan <maowenan@huawei.com>
>> ---
>>  drivers/staging/kpc2000/kpc_spi/spi_driver.c | 3 ---
>>  1 file changed, 3 deletions(-)
> 
> What is [PATCH net] in the subject for?  This is not a networking driver
> :(
Sorry, this is my mistake.
> 
> 
> .
> 


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH net] staging: Remove set but not used variable =?UTF-8?B?IOKAmHN0YXR1c+KAmQ==
@ 2019-05-25  6:39     ` maowenan
  0 siblings, 0 replies; 20+ messages in thread
From: maowenan @ 2019-05-25  6:39 UTC (permalink / raw)
  To: Greg KH; +Cc: jeremy, devel, kernel-janitors, linux-kernel



On 2019/5/25 13:01, Greg KH wrote:
> On Sat, May 25, 2019 at 12:26:42PM +0800, Mao Wenan wrote:
>> Fixes gcc '-Wunused-but-set-variable' warning:
>>
>> drivers/staging/kpc2000/kpc_spi/spi_driver.c: In function
>> ‘kp_spi_transfer_one_message’:
>> drivers/staging/kpc2000/kpc_spi/spi_driver.c:282:9: warning: variable
>> ‘status’ set but not used [-Wunused-but-set-variable]
>>      int status = 0;
>>          ^~~~~~
>> The variable 'status' is not used any more, remve it.
>>
>> Signed-off-by: Mao Wenan <maowenan@huawei.com>
>> ---
>>  drivers/staging/kpc2000/kpc_spi/spi_driver.c | 3 ---
>>  1 file changed, 3 deletions(-)
> 
> What is [PATCH net] in the subject for?  This is not a networking driver
> :(
Sorry, this is my mistake.
> 
> 
> .
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH -next v2] staging: kpc2000: Remove set but not used variable ‘status’
  2019-05-25  4:26 ` [PATCH net] staging: Remove set but not used =?UTF-8?q?=20variable=20=E2=80=98 Mao Wenan
@ 2019-05-25  8:13   ` Mao Wenan
  -1 siblings, 0 replies; 20+ messages in thread
From: Mao Wenan @ 2019-05-25  8:13 UTC (permalink / raw)
  To: gregkh, jeremy; +Cc: devel, linux-kernel, kernel-janitors, Mao Wenan

Fixes gcc '-Wunused-but-set-variable' warning:

drivers/staging/kpc2000/kpc_spi/spi_driver.c: In function
‘kp_spi_transfer_one_message’:
drivers/staging/kpc2000/kpc_spi/spi_driver.c:282:9: warning: variable
‘status’ set but not used [-Wunused-but-set-variable]
     int status = 0;
         ^~~~~~
The variable 'status' is not used any more, remve it.

Signed-off-by: Mao Wenan <maowenan@huawei.com>
---
 v2: change the subject of the patch.
---
 drivers/staging/kpc2000/kpc_spi/spi_driver.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc_spi/spi_driver.c b/drivers/staging/kpc2000/kpc_spi/spi_driver.c
index 86df16547a92..16f9518f8d63 100644
--- a/drivers/staging/kpc2000/kpc_spi/spi_driver.c
+++ b/drivers/staging/kpc2000/kpc_spi/spi_driver.c
@@ -279,7 +279,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
     struct kp_spi       *kpspi;
     struct spi_transfer *transfer;
     union kp_spi_config sc;
-    int status = 0;
     
     spidev = m->spi;
     kpspi = spi_master_get_devdata(master);
@@ -332,7 +331,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
     /* do the transfers for this message */
     list_for_each_entry(transfer, &m->transfers, transfer_list) {
         if (transfer->tx_buf == NULL && transfer->rx_buf == NULL && transfer->len) {
-            status = -EINVAL;
             break;
         }
         
@@ -370,7 +368,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
             m->actual_length += count;
             
             if (count != transfer->len) {
-                status = -EIO;
                 break;
             }
         }
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH -next v2] staging: kpc2000: Remove set b =?UTF-8?q?ut=20not=20used=20vari
@ 2019-05-25  8:13   ` Mao Wenan
  0 siblings, 0 replies; 20+ messages in thread
From: Mao Wenan @ 2019-05-25  8:13 UTC (permalink / raw)
  To: gregkh, jeremy; +Cc: devel, linux-kernel, kernel-janitors, Mao Wenan

Fixes gcc '-Wunused-but-set-variable' warning:

drivers/staging/kpc2000/kpc_spi/spi_driver.c: In function
‘kp_spi_transfer_one_message’:
drivers/staging/kpc2000/kpc_spi/spi_driver.c:282:9: warning: variable
‘status’ set but not used [-Wunused-but-set-variable]
     int status = 0;
         ^~~~~~
The variable 'status' is not used any more, remve it.

Signed-off-by: Mao Wenan <maowenan@huawei.com>
---
 v2: change the subject of the patch.
---
 drivers/staging/kpc2000/kpc_spi/spi_driver.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc_spi/spi_driver.c b/drivers/staging/kpc2000/kpc_spi/spi_driver.c
index 86df16547a92..16f9518f8d63 100644
--- a/drivers/staging/kpc2000/kpc_spi/spi_driver.c
+++ b/drivers/staging/kpc2000/kpc_spi/spi_driver.c
@@ -279,7 +279,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
     struct kp_spi       *kpspi;
     struct spi_transfer *transfer;
     union kp_spi_config sc;
-    int status = 0;
     
     spidev = m->spi;
     kpspi = spi_master_get_devdata(master);
@@ -332,7 +331,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
     /* do the transfers for this message */
     list_for_each_entry(transfer, &m->transfers, transfer_list) {
         if (transfer->tx_buf = NULL && transfer->rx_buf = NULL && transfer->len) {
-            status = -EINVAL;
             break;
         }
         
@@ -370,7 +368,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
             m->actual_length += count;
             
             if (count != transfer->len) {
-                status = -EIO;
                 break;
             }
         }
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH net] staging: Remove set but not used variable ‘status’
  2019-05-25  4:26 ` [PATCH net] staging: Remove set but not used =?UTF-8?q?=20variable=20=E2=80=98 Mao Wenan
@ 2019-05-25 12:59   ` Sven Van Asbroeck
  -1 siblings, 0 replies; 20+ messages in thread
From: Sven Van Asbroeck @ 2019-05-25 12:59 UTC (permalink / raw)
  To: Mao Wenan
  Cc: Greg KH, Jeremy Sowden, devel, Linux Kernel Mailing List,
	kernel-janitors, Matt Sickler

On Sat, May 25, 2019 at 12:20 AM Mao Wenan <maowenan@huawei.com> wrote:
>
> The variable 'status' is not used any more, remve it.

>      /* do the transfers for this message */
>      list_for_each_entry(transfer, &m->transfers, transfer_list) {
>          if (transfer->tx_buf == NULL && transfer->rx_buf == NULL && transfer->len) {
> -            status = -EINVAL;
>              break;
>          }

This looks like an error condition that's not reported to the spi core.

Instead of removing the status variable (which also removes the error value!),
maybe this should be reported to the spi core instead ?

Other spi drivers appear to do the following on the error path:
m->status = status;
return status;

>
> @@ -370,7 +368,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
>
>              if (count != transfer->len) {
> -                status = -EIO;
>                  break;

Same issue here.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH net] staging: Remove set but not used var =?UTF-8?Q?iable_=E2=80=98st
@ 2019-05-25 12:59   ` Sven Van Asbroeck
  0 siblings, 0 replies; 20+ messages in thread
From: Sven Van Asbroeck @ 2019-05-25 12:59 UTC (permalink / raw)
  To: Mao Wenan
  Cc: Greg KH, Jeremy Sowden, devel, Linux Kernel Mailing List,
	kernel-janitors, Matt Sickler

On Sat, May 25, 2019 at 12:20 AM Mao Wenan <maowenan@huawei.com> wrote:
>
> The variable 'status' is not used any more, remve it.

>      /* do the transfers for this message */
>      list_for_each_entry(transfer, &m->transfers, transfer_list) {
>          if (transfer->tx_buf = NULL && transfer->rx_buf = NULL && transfer->len) {
> -            status = -EINVAL;
>              break;
>          }

This looks like an error condition that's not reported to the spi core.

Instead of removing the status variable (which also removes the error value!),
maybe this should be reported to the spi core instead ?

Other spi drivers appear to do the following on the error path:
m->status = status;
return status;

>
> @@ -370,7 +368,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
>
>              if (count != transfer->len) {
> -                status = -EIO;
>                  break;

Same issue here.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH net] staging: Remove set but not used variable ‘status’
  2019-05-25 12:59   ` [PATCH net] staging: Remove set but not used var =?UTF-8?Q?iable_=E2=80=98st Sven Van Asbroeck
@ 2019-05-27  2:33     ` maowenan
  -1 siblings, 0 replies; 20+ messages in thread
From: maowenan @ 2019-05-27  2:33 UTC (permalink / raw)
  To: Sven Van Asbroeck
  Cc: Greg KH, Jeremy Sowden, devel, Linux Kernel Mailing List,
	kernel-janitors, Matt Sickler



On 2019/5/25 20:59, Sven Van Asbroeck wrote:
> On Sat, May 25, 2019 at 12:20 AM Mao Wenan <maowenan@huawei.com> wrote:
>>
>> The variable 'status' is not used any more, remve it.
> 
>>      /* do the transfers for this message */
>>      list_for_each_entry(transfer, &m->transfers, transfer_list) {
>>          if (transfer->tx_buf == NULL && transfer->rx_buf == NULL && transfer->len) {
>> -            status = -EINVAL;
>>              break;
>>          }
> 
> This looks like an error condition that's not reported to the spi core.
> 
> Instead of removing the status variable (which also removes the error value!),
> maybe this should be reported to the spi core instead ?
> 
> Other spi drivers appear to do the following on the error path:
> m->status = status;
> return status;

I have reviewed the code again, and it is good idea to store m->status in error path, like below?

@@ -374,7 +374,7 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
     list_for_each_entry(transfer, &m->transfers, transfer_list) {
         if (transfer->tx_buf == NULL && transfer->rx_buf == NULL && transfer->len) {
             status = -EINVAL;
-            break;
+            goto error;
         }

         /* transfer */
@@ -412,7 +412,7 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)

             if (count != transfer->len) {
                 status = -EIO;
-                break;
+                goto error;
             }
         }


...

     /* done work */
     spi_finalize_current_message(master);
     return 0;
+
+ error:
+    m->status = status;
+    return status;

 }


> 
>>
>> @@ -370,7 +368,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
>>
>>              if (count != transfer->len) {
>> -                status = -EIO;
>>                  break;
> 
> Same issue here.
> 
> 


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH net] staging: Remove set but not used variable =?UTF-8?B?IOKAmHN0YXR1c+KAmQ==
@ 2019-05-27  2:33     ` maowenan
  0 siblings, 0 replies; 20+ messages in thread
From: maowenan @ 2019-05-27  2:33 UTC (permalink / raw)
  To: Sven Van Asbroeck
  Cc: Greg KH, Jeremy Sowden, devel, Linux Kernel Mailing List,
	kernel-janitors, Matt Sickler



On 2019/5/25 20:59, Sven Van Asbroeck wrote:
> On Sat, May 25, 2019 at 12:20 AM Mao Wenan <maowenan@huawei.com> wrote:
>>
>> The variable 'status' is not used any more, remve it.
> 
>>      /* do the transfers for this message */
>>      list_for_each_entry(transfer, &m->transfers, transfer_list) {
>>          if (transfer->tx_buf = NULL && transfer->rx_buf = NULL && transfer->len) {
>> -            status = -EINVAL;
>>              break;
>>          }
> 
> This looks like an error condition that's not reported to the spi core.
> 
> Instead of removing the status variable (which also removes the error value!),
> maybe this should be reported to the spi core instead ?
> 
> Other spi drivers appear to do the following on the error path:
> m->status = status;
> return status;

I have reviewed the code again, and it is good idea to store m->status in error path, like below?

@@ -374,7 +374,7 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
     list_for_each_entry(transfer, &m->transfers, transfer_list) {
         if (transfer->tx_buf = NULL && transfer->rx_buf = NULL && transfer->len) {
             status = -EINVAL;
-            break;
+            goto error;
         }

         /* transfer */
@@ -412,7 +412,7 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)

             if (count != transfer->len) {
                 status = -EIO;
-                break;
+                goto error;
             }
         }


...

     /* done work */
     spi_finalize_current_message(master);
     return 0;
+
+ error:
+    m->status = status;
+    return status;

 }


> 
>>
>> @@ -370,7 +368,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
>>
>>              if (count != transfer->len) {
>> -                status = -EIO;
>>                  break;
> 
> Same issue here.
> 
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH -next v2] staging: kpc2000: Remove set but not used variable ‘status’
  2019-05-25  8:13   ` [PATCH -next v2] staging: kpc2000: Remove set b =?UTF-8?q?ut=20not=20used=20vari Mao Wenan
@ 2019-05-28  2:09     ` maowenan
  -1 siblings, 0 replies; 20+ messages in thread
From: maowenan @ 2019-05-28  2:09 UTC (permalink / raw)
  To: gregkh, jeremy; +Cc: devel, linux-kernel, kernel-janitors, Sven Van Asbroeck

please ignore v2 version.
I will send v3 later according to Sven Van Asbroeck 's comments.

On 2019/5/25 16:13, Mao Wenan wrote:
> Fixes gcc '-Wunused-but-set-variable' warning:
> 
> drivers/staging/kpc2000/kpc_spi/spi_driver.c: In function
> ‘kp_spi_transfer_one_message’:
> drivers/staging/kpc2000/kpc_spi/spi_driver.c:282:9: warning: variable
> ‘status’ set but not used [-Wunused-but-set-variable]
>      int status = 0;
>          ^~~~~~
> The variable 'status' is not used any more, remve it.
> 
> Signed-off-by: Mao Wenan <maowenan@huawei.com>
> ---
>  v2: change the subject of the patch.
> ---
>  drivers/staging/kpc2000/kpc_spi/spi_driver.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/drivers/staging/kpc2000/kpc_spi/spi_driver.c b/drivers/staging/kpc2000/kpc_spi/spi_driver.c
> index 86df16547a92..16f9518f8d63 100644
> --- a/drivers/staging/kpc2000/kpc_spi/spi_driver.c
> +++ b/drivers/staging/kpc2000/kpc_spi/spi_driver.c
> @@ -279,7 +279,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
>      struct kp_spi       *kpspi;
>      struct spi_transfer *transfer;
>      union kp_spi_config sc;
> -    int status = 0;
>      
>      spidev = m->spi;
>      kpspi = spi_master_get_devdata(master);
> @@ -332,7 +331,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
>      /* do the transfers for this message */
>      list_for_each_entry(transfer, &m->transfers, transfer_list) {
>          if (transfer->tx_buf == NULL && transfer->rx_buf == NULL && transfer->len) {
> -            status = -EINVAL;
>              break;
>          }
>          
> @@ -370,7 +368,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
>              m->actual_length += count;
>              
>              if (count != transfer->len) {
> -                status = -EIO;
>                  break;
>              }
>          }
> 


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH -next v2] staging: kpc2000: Remove set but not =?UTF-8?B?IHVzZWQgdmFyaWFibGUg
@ 2019-05-28  2:09     ` maowenan
  0 siblings, 0 replies; 20+ messages in thread
From: maowenan @ 2019-05-28  2:09 UTC (permalink / raw)
  To: gregkh, jeremy; +Cc: devel, linux-kernel, kernel-janitors, Sven Van Asbroeck

please ignore v2 version.
I will send v3 later according to Sven Van Asbroeck 's comments.

On 2019/5/25 16:13, Mao Wenan wrote:
> Fixes gcc '-Wunused-but-set-variable' warning:
> 
> drivers/staging/kpc2000/kpc_spi/spi_driver.c: In function
> ‘kp_spi_transfer_one_message’:
> drivers/staging/kpc2000/kpc_spi/spi_driver.c:282:9: warning: variable
> ‘status’ set but not used [-Wunused-but-set-variable]
>      int status = 0;
>          ^~~~~~
> The variable 'status' is not used any more, remve it.
> 
> Signed-off-by: Mao Wenan <maowenan@huawei.com>
> ---
>  v2: change the subject of the patch.
> ---
>  drivers/staging/kpc2000/kpc_spi/spi_driver.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/drivers/staging/kpc2000/kpc_spi/spi_driver.c b/drivers/staging/kpc2000/kpc_spi/spi_driver.c
> index 86df16547a92..16f9518f8d63 100644
> --- a/drivers/staging/kpc2000/kpc_spi/spi_driver.c
> +++ b/drivers/staging/kpc2000/kpc_spi/spi_driver.c
> @@ -279,7 +279,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
>      struct kp_spi       *kpspi;
>      struct spi_transfer *transfer;
>      union kp_spi_config sc;
> -    int status = 0;
>      
>      spidev = m->spi;
>      kpspi = spi_master_get_devdata(master);
> @@ -332,7 +331,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
>      /* do the transfers for this message */
>      list_for_each_entry(transfer, &m->transfers, transfer_list) {
>          if (transfer->tx_buf = NULL && transfer->rx_buf = NULL && transfer->len) {
> -            status = -EINVAL;
>              break;
>          }
>          
> @@ -370,7 +368,6 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
>              m->actual_length += count;
>              
>              if (count != transfer->len) {
> -                status = -EIO;
>                  break;
>              }
>          }
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH -next v3 2/2] staging: kpc2000: replace white spaces with tabs for kpc2000_spi.c
  2019-05-28  8:02     ` Mao Wenan
@ 2019-05-28  8:02       ` Mao Wenan
  -1 siblings, 0 replies; 20+ messages in thread
From: Mao Wenan @ 2019-05-28  7:54 UTC (permalink / raw)
  To: gregkh, jeremy
  Cc: thesven73, devel, linux-kernel, kernel-janitors, matt.sickler, Mao Wenan

There are multiple wrong formats in kpc2000_spi.c,
is time to do clean work for it.

Signed-off-by: Mao Wenan <maowenan@huawei.com>
---
 drivers/staging/kpc2000/kpc2000_spi.c | 722 +++++++++++++-------------
 1 file changed, 361 insertions(+), 361 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000_spi.c b/drivers/staging/kpc2000/kpc2000_spi.c
index 628a447642ad..9a23808ffaa1 100644
--- a/drivers/staging/kpc2000/kpc2000_spi.c
+++ b/drivers/staging/kpc2000/kpc2000_spi.c
@@ -113,59 +113,59 @@ struct kp_spi {
 
 
 struct kp_spi_controller_state {
-    void __iomem   *base;
-    unsigned long   phys;
-    unsigned char   chip_select;
-    int             word_len;
-    s64             conf_cache;
+	void __iomem   *base;
+	unsigned long   phys;
+	unsigned char   chip_select;
+	int             word_len;
+	s64             conf_cache;
 };
 
 
 union kp_spi_config {
-    /* use this to access individual elements */
-    struct __attribute__((packed)) spi_config_bitfield {
-        unsigned int pha       : 1; /* spim_clk Phase      */
-        unsigned int pol       : 1; /* spim_clk Polarity   */
-        unsigned int epol      : 1; /* spim_csx Polarity   */
-        unsigned int dpe       : 1; /* Transmission Enable */
-        unsigned int wl        : 5; /* Word Length         */
-        unsigned int           : 3;
-        unsigned int trm       : 2; /* TxRx Mode           */
-        unsigned int cs        : 4; /* Chip Select         */
-        unsigned int wcnt      : 7; /* Word Count          */
-        unsigned int ffen      : 1; /* FIFO Enable         */
-        unsigned int spi_en    : 1; /* SPI Enable          */
-        unsigned int           : 5;
-    } bitfield;
-    /* use this to grab the whole register */
-    u32 reg;
+	/* use this to access individual elements */
+	struct __attribute__((packed)) spi_config_bitfield {
+		unsigned int pha       : 1; /* spim_clk Phase      */
+		unsigned int pol       : 1; /* spim_clk Polarity   */
+		unsigned int epol      : 1; /* spim_csx Polarity   */
+		unsigned int dpe       : 1; /* Transmission Enable */
+		unsigned int wl        : 5; /* Word Length         */
+		unsigned int           : 3;
+		unsigned int trm       : 2; /* TxRx Mode           */
+		unsigned int cs        : 4; /* Chip Select         */
+		unsigned int wcnt      : 7; /* Word Count          */
+		unsigned int ffen      : 1; /* FIFO Enable         */
+		unsigned int spi_en    : 1; /* SPI Enable          */
+		unsigned int           : 5;
+	} bitfield;
+	/* use this to grab the whole register */
+	u32 reg;
 };
 
 
 
 union kp_spi_status {
-    struct __attribute__((packed)) spi_status_bitfield {
-        unsigned int rx    :  1; /* Rx Status       */
-        unsigned int tx    :  1; /* Tx Status       */
-        unsigned int eo    :  1; /* End of Transfer */
-        unsigned int       :  1;
-        unsigned int txffe :  1; /* Tx FIFO Empty   */
-        unsigned int txfff :  1; /* Tx FIFO Full    */
-        unsigned int rxffe :  1; /* Rx FIFO Empty   */
-        unsigned int rxfff :  1; /* Rx FIFO Full    */
-        unsigned int       : 24;
-    } bitfield;
-    u32 reg;
+	struct __attribute__((packed)) spi_status_bitfield {
+		unsigned int rx    :  1; /* Rx Status       */
+		unsigned int tx    :  1; /* Tx Status       */
+		unsigned int eo    :  1; /* End of Transfer */
+		unsigned int       :  1;
+		unsigned int txffe :  1; /* Tx FIFO Empty   */
+		unsigned int txfff :  1; /* Tx FIFO Full    */
+		unsigned int rxffe :  1; /* Rx FIFO Empty   */
+		unsigned int rxfff :  1; /* Rx FIFO Full    */
+		unsigned int       : 24;
+	} bitfield;
+	u32 reg;
 };
 
 
 
 union kp_spi_ffctrl {
-    struct __attribute__((packed)) spi_ffctrl_bitfield {
-        unsigned int ffstart :  1; /* FIFO Start */
-        unsigned int         : 31;
-    } bitfield;
-    u32 reg;
+	struct __attribute__((packed)) spi_ffctrl_bitfield {
+		unsigned int ffstart :  1; /* FIFO Start */
+		unsigned int         : 31;
+	} bitfield;
+	u32 reg;
 };
 
 
@@ -173,276 +173,276 @@ union kp_spi_ffctrl {
 /***************
  * SPI Helpers *
  ***************/
-static inline int
+	static inline int
 kp_spi_bytes_per_word(int word_len)
 {
-    if (word_len <= 8){
-        return 1;
-    }
-    else if (word_len <= 16) {
-        return 2;
-    }
-    else { /* word_len <= 32 */
-        return 4;
-    }
+	if (word_len <= 8){
+		return 1;
+	}
+	else if (word_len <= 16) {
+		return 2;
+	}
+	else { /* word_len <= 32 */
+		return 4;
+	}
 }
 
-static inline u64
+	static inline u64
 kp_spi_read_reg(struct kp_spi_controller_state *cs, int idx)
 {
-    u64 __iomem *addr = cs->base;
-    u64 val;
-
-    addr += idx;
-    if ((idx = KP_SPI_REG_CONFIG) && (cs->conf_cache >= 0)){
-        return cs->conf_cache;
-    }
-    val = readq((void*)addr);
-    return val;
+	u64 __iomem *addr = cs->base;
+	u64 val;
+
+	addr += idx;
+	if ((idx = KP_SPI_REG_CONFIG) && (cs->conf_cache >= 0)){
+		return cs->conf_cache;
+	}
+	val = readq((void*)addr);
+	return val;
 }
 
-static inline void
+	static inline void
 kp_spi_write_reg(struct kp_spi_controller_state *cs, int idx, u64 val)
 {
-    u64 __iomem *addr = cs->base;
-    addr += idx;
-    writeq(val, (void*)addr);
-    if (idx = KP_SPI_REG_CONFIG)
-        cs->conf_cache = val;
+	u64 __iomem *addr = cs->base;
+	addr += idx;
+	writeq(val, (void*)addr);
+	if (idx = KP_SPI_REG_CONFIG)
+		cs->conf_cache = val;
 }
 
-static int
+	static int
 kp_spi_wait_for_reg_bit(struct kp_spi_controller_state *cs, int idx, unsigned long bit)
 {
-    unsigned long timeout;
-    timeout = jiffies + msecs_to_jiffies(1000);
-    while (!(kp_spi_read_reg(cs, idx) & bit)) {
-        if (time_after(jiffies, timeout)) {
-            if (!(kp_spi_read_reg(cs, idx) & bit)) {
-                return -ETIMEDOUT;
-            } else {
-                return 0;
-            }
-        }
-        cpu_relax();
-    }
-    return 0;
+	unsigned long timeout;
+	timeout = jiffies + msecs_to_jiffies(1000);
+	while (!(kp_spi_read_reg(cs, idx) & bit)) {
+		if (time_after(jiffies, timeout)) {
+			if (!(kp_spi_read_reg(cs, idx) & bit)) {
+				return -ETIMEDOUT;
+			} else {
+				return 0;
+			}
+		}
+		cpu_relax();
+	}
+	return 0;
 }
 
-static unsigned
+	static unsigned
 kp_spi_txrx_pio(struct spi_device *spidev, struct spi_transfer *transfer)
 {
-    struct kp_spi_controller_state *cs = spidev->controller_state;
-    unsigned int count = transfer->len;
-    unsigned int c = count;
-    
-    int i;
-    u8 *rx       = transfer->rx_buf;
-    const u8 *tx = transfer->tx_buf;
-    int processed = 0;
-    
-    if (tx) {
-        for (i = 0 ; i < c ; i++) {
-            char val = *tx++;
-            
-            if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_TXS) < 0) {
-                goto out;
-            }
-            
-            kp_spi_write_reg(cs, KP_SPI_REG_TXDATA, val);
-            processed++;
-        }
-    }
-    else if(rx) {
-        for (i = 0 ; i < c ; i++) {
-            char test=0;
-            
-            kp_spi_write_reg(cs, KP_SPI_REG_TXDATA, 0x00);
-            
-            if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_RXS) < 0) {
-                goto out;
-            }
-            
-            test = kp_spi_read_reg(cs, KP_SPI_REG_RXDATA);
-            *rx++ = test;
-            processed++;
-        }
-    }
-    
-    if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_EOT) < 0) {
-        //TODO: Figure out how to abort transaction??  This has never happened in practice though...
-    }
-    
- out:
-    return processed;
+	struct kp_spi_controller_state *cs = spidev->controller_state;
+	unsigned int count = transfer->len;
+	unsigned int c = count;
+
+	int i;
+	u8 *rx       = transfer->rx_buf;
+	const u8 *tx = transfer->tx_buf;
+	int processed = 0;
+
+	if (tx) {
+		for (i = 0 ; i < c ; i++) {
+			char val = *tx++;
+
+			if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_TXS) < 0) {
+				goto out;
+			}
+
+			kp_spi_write_reg(cs, KP_SPI_REG_TXDATA, val);
+			processed++;
+		}
+	}
+	else if(rx) {
+		for (i = 0 ; i < c ; i++) {
+			char test=0;
+
+			kp_spi_write_reg(cs, KP_SPI_REG_TXDATA, 0x00);
+
+			if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_RXS) < 0) {
+				goto out;
+			}
+
+			test = kp_spi_read_reg(cs, KP_SPI_REG_RXDATA);
+			*rx++ = test;
+			processed++;
+		}
+	}
+
+	if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_EOT) < 0) {
+		//TODO: Figure out how to abort transaction??  This has never happened in practice though...
+	}
+
+out:
+	return processed;
 }
 
 /*****************
  * SPI Functions *
  *****************/
-static int
+	static int
 kp_spi_setup(struct spi_device *spidev)
 {
-    union kp_spi_config sc;
-    struct kp_spi *kpspi = spi_master_get_devdata(spidev->master);
-    struct kp_spi_controller_state *cs;
-    
-    /* setup controller state */
-    cs = spidev->controller_state;
-    if (!cs) {
-        cs = kzalloc(sizeof(*cs), GFP_KERNEL);
-        if(!cs) {
-            return -ENOMEM;
-        }
-        cs->base = kpspi->base;
-        cs->phys = kpspi->phys;
-        cs->chip_select = spidev->chip_select;
-        cs->word_len = spidev->bits_per_word;
-        cs->conf_cache = -1;
-        spidev->controller_state = cs;
-    }
-    
-    /* set config register */
-    sc.bitfield.wl = spidev->bits_per_word - 1;
-    sc.bitfield.cs = spidev->chip_select;
-    sc.bitfield.spi_en = 0;
-    sc.bitfield.trm = 0;
-    sc.bitfield.ffen = 0;
-    kp_spi_write_reg(spidev->controller_state, KP_SPI_REG_CONFIG, sc.reg);
-    return 0;
+	union kp_spi_config sc;
+	struct kp_spi *kpspi = spi_master_get_devdata(spidev->master);
+	struct kp_spi_controller_state *cs;
+
+	/* setup controller state */
+	cs = spidev->controller_state;
+	if (!cs) {
+		cs = kzalloc(sizeof(*cs), GFP_KERNEL);
+		if(!cs) {
+			return -ENOMEM;
+		}
+		cs->base = kpspi->base;
+		cs->phys = kpspi->phys;
+		cs->chip_select = spidev->chip_select;
+		cs->word_len = spidev->bits_per_word;
+		cs->conf_cache = -1;
+		spidev->controller_state = cs;
+	}
+
+	/* set config register */
+	sc.bitfield.wl = spidev->bits_per_word - 1;
+	sc.bitfield.cs = spidev->chip_select;
+	sc.bitfield.spi_en = 0;
+	sc.bitfield.trm = 0;
+	sc.bitfield.ffen = 0;
+	kp_spi_write_reg(spidev->controller_state, KP_SPI_REG_CONFIG, sc.reg);
+	return 0;
 }
 
-static int
+	static int
 kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
 {
-    struct kp_spi_controller_state *cs;
-    struct spi_device   *spidev;
-    struct kp_spi       *kpspi;
-    struct spi_transfer *transfer;
-    union kp_spi_config sc;
-    int status = 0;
-    
-    spidev = m->spi;
-    kpspi = spi_master_get_devdata(master);
-    m->actual_length = 0;
-    m->status = 0;
-    
-    cs = spidev->controller_state;
-    
-    /* reject invalid messages and transfers */
-    if (list_empty(&m->transfers)) {
-        return -EINVAL;
-    }
-    
-    /* validate input */
-    list_for_each_entry(transfer, &m->transfers, transfer_list) {
-        const void *tx_buf = transfer->tx_buf;
-        void       *rx_buf = transfer->rx_buf;
-        unsigned    len = transfer->len;
-        
-        if (transfer->speed_hz > KP_SPI_CLK || (len && !(rx_buf || tx_buf))) {
-            dev_dbg(kpspi->dev, "  transfer: %d Hz, %d %s%s, %d bpw\n",
-                    transfer->speed_hz,
-                    len,
-                    tx_buf ? "tx" : "",
-                    rx_buf ? "rx" : "",
-                    transfer->bits_per_word);
-            dev_dbg(kpspi->dev, "  transfer -EINVAL\n");
-            return -EINVAL;
-        }
-        if (transfer->speed_hz && (transfer->speed_hz < (KP_SPI_CLK >> 15))) {
-            dev_dbg(kpspi->dev, "speed_hz %d below minimum %d Hz\n",
-                    transfer->speed_hz,
-                    KP_SPI_CLK >> 15);
-            dev_dbg(kpspi->dev, "  speed_hz -EINVAL\n");
-            return -EINVAL;
-        }
-    }
-    
-    /* assert chip select to start the sequence*/
-    sc.reg = kp_spi_read_reg(cs, KP_SPI_REG_CONFIG);
-    sc.bitfield.spi_en = 1;
-    kp_spi_write_reg(cs, KP_SPI_REG_CONFIG, sc.reg);
-    
-    /* work */
-    if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_EOT) < 0) {
-        dev_info(kpspi->dev, "EOT timed out\n");
-        goto out;
-    }
-    
-    /* do the transfers for this message */
-    list_for_each_entry(transfer, &m->transfers, transfer_list) {
-        if (transfer->tx_buf = NULL && transfer->rx_buf = NULL && transfer->len) {
-            status = -EINVAL;
-            goto error;
-        }
-        
-        /* transfer */
-        if (transfer->len) {
-            unsigned int word_len = spidev->bits_per_word;
-            unsigned count;
-            
-            /* set up the transfer... */
-            sc.reg = kp_spi_read_reg(cs, KP_SPI_REG_CONFIG);
-            
-            /* ...direction */
-            if (transfer->tx_buf) {
-                sc.bitfield.trm = KP_SPI_REG_CONFIG_TRM_TX;
-            }
-            else if (transfer->rx_buf) {
-                sc.bitfield.trm = KP_SPI_REG_CONFIG_TRM_RX;
-            }
-            
-            /* ...word length */
-            if (transfer->bits_per_word) {
-                word_len = transfer->bits_per_word;
-            }
-            cs->word_len = word_len;
-            sc.bitfield.wl = word_len-1;
-            
-            /* ...chip select */
-            sc.bitfield.cs = spidev->chip_select;
-            
-            /* ...and write the new settings */
-            kp_spi_write_reg(cs, KP_SPI_REG_CONFIG, sc.reg);
-            
-            /* do the transfer */
-            count = kp_spi_txrx_pio(spidev, transfer);
-            m->actual_length += count;
-            
-            if (count != transfer->len) {
-                status = -EIO;
-                goto error;
-            }
-        }
-        
-        if (transfer->delay_usecs) {
-            udelay(transfer->delay_usecs);
-        }
-    }
-    
-    /* de-assert chip select to end the sequence */
-    sc.reg = kp_spi_read_reg(cs, KP_SPI_REG_CONFIG);
-    sc.bitfield.spi_en = 0;
-    kp_spi_write_reg(cs, KP_SPI_REG_CONFIG, sc.reg);
-    
- out:
-    /* done work */
-    spi_finalize_current_message(master);
-    return 0;
-
- error:
-    m->status = status;
-    return status;
+	struct kp_spi_controller_state *cs;
+	struct spi_device   *spidev;
+	struct kp_spi       *kpspi;
+	struct spi_transfer *transfer;
+	union kp_spi_config sc;
+	int status = 0;
+
+	spidev = m->spi;
+	kpspi = spi_master_get_devdata(master);
+	m->actual_length = 0;
+	m->status = 0;
+
+	cs = spidev->controller_state;
+
+	/* reject invalid messages and transfers */
+	if (list_empty(&m->transfers)) {
+		return -EINVAL;
+	}
+
+	/* validate input */
+	list_for_each_entry(transfer, &m->transfers, transfer_list) {
+		const void *tx_buf = transfer->tx_buf;
+		void       *rx_buf = transfer->rx_buf;
+		unsigned    len = transfer->len;
+
+		if (transfer->speed_hz > KP_SPI_CLK || (len && !(rx_buf || tx_buf))) {
+			dev_dbg(kpspi->dev, "  transfer: %d Hz, %d %s%s, %d bpw\n",
+					transfer->speed_hz,
+					len,
+					tx_buf ? "tx" : "",
+					rx_buf ? "rx" : "",
+					transfer->bits_per_word);
+			dev_dbg(kpspi->dev, "  transfer -EINVAL\n");
+			return -EINVAL;
+		}
+		if (transfer->speed_hz && (transfer->speed_hz < (KP_SPI_CLK >> 15))) {
+			dev_dbg(kpspi->dev, "speed_hz %d below minimum %d Hz\n",
+					transfer->speed_hz,
+					KP_SPI_CLK >> 15);
+			dev_dbg(kpspi->dev, "  speed_hz -EINVAL\n");
+			return -EINVAL;
+		}
+	}
+
+	/* assert chip select to start the sequence*/
+	sc.reg = kp_spi_read_reg(cs, KP_SPI_REG_CONFIG);
+	sc.bitfield.spi_en = 1;
+	kp_spi_write_reg(cs, KP_SPI_REG_CONFIG, sc.reg);
+
+	/* work */
+	if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_EOT) < 0) {
+		dev_info(kpspi->dev, "EOT timed out\n");
+		goto out;
+	}
+
+	/* do the transfers for this message */
+	list_for_each_entry(transfer, &m->transfers, transfer_list) {
+		if (transfer->tx_buf = NULL && transfer->rx_buf = NULL && transfer->len) {
+			status = -EINVAL;
+			goto error;
+		}
+
+		/* transfer */
+		if (transfer->len) {
+			unsigned int word_len = spidev->bits_per_word;
+			unsigned count;
+
+			/* set up the transfer... */
+			sc.reg = kp_spi_read_reg(cs, KP_SPI_REG_CONFIG);
+
+			/* ...direction */
+			if (transfer->tx_buf) {
+				sc.bitfield.trm = KP_SPI_REG_CONFIG_TRM_TX;
+			}
+			else if (transfer->rx_buf) {
+				sc.bitfield.trm = KP_SPI_REG_CONFIG_TRM_RX;
+			}
+
+			/* ...word length */
+			if (transfer->bits_per_word) {
+				word_len = transfer->bits_per_word;
+			}
+			cs->word_len = word_len;
+			sc.bitfield.wl = word_len-1;
+
+			/* ...chip select */
+			sc.bitfield.cs = spidev->chip_select;
+
+			/* ...and write the new settings */
+			kp_spi_write_reg(cs, KP_SPI_REG_CONFIG, sc.reg);
+
+			/* do the transfer */
+			count = kp_spi_txrx_pio(spidev, transfer);
+			m->actual_length += count;
+
+			if (count != transfer->len) {
+				status = -EIO;
+				goto error;
+			}
+		}
+
+		if (transfer->delay_usecs) {
+			udelay(transfer->delay_usecs);
+		}
+	}
+
+	/* de-assert chip select to end the sequence */
+	sc.reg = kp_spi_read_reg(cs, KP_SPI_REG_CONFIG);
+	sc.bitfield.spi_en = 0;
+	kp_spi_write_reg(cs, KP_SPI_REG_CONFIG, sc.reg);
+
+out:
+	/* done work */
+	spi_finalize_current_message(master);
+	return 0;
+
+error:
+	m->status = status;
+	return status;
 }
 
-static void
+	static void
 kp_spi_cleanup(struct spi_device *spidev)
 {
-    struct kp_spi_controller_state *cs = spidev->controller_state;
-    if (cs) {
-        kfree(cs);
-    }
+	struct kp_spi_controller_state *cs = spidev->controller_state;
+	if (cs) {
+		kfree(cs);
+	}
 }
 
 
@@ -450,101 +450,101 @@ kp_spi_cleanup(struct spi_device *spidev)
 /******************
  * Probe / Remove *
  ******************/
-static int
+	static int
 kp_spi_probe(struct platform_device *pldev)
 {
-    struct kpc_core_device_platdata *drvdata;
-    struct spi_master *master;
-    struct kp_spi *kpspi;
-    struct resource *r;
-    int status = 0;
-    int i;
-
-    drvdata = pldev->dev.platform_data;
-    if (!drvdata){
-        dev_err(&pldev->dev, "kp_spi_probe: platform_data is NULL!\n");
-        return -ENODEV;
-    }
-    
-    master = spi_alloc_master(&pldev->dev, sizeof(struct kp_spi));
-    if (master = NULL) {
-        dev_err(&pldev->dev, "kp_spi_probe: master allocation failed\n");
-        return -ENOMEM;
-    }
-    
-    /* set up the spi functions */
-    master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
-    master->bits_per_word_mask = (unsigned int)SPI_BPW_RANGE_MASK(4, 32);
-    master->setup = kp_spi_setup;
-    master->transfer_one_message = kp_spi_transfer_one_message;
-    master->cleanup = kp_spi_cleanup;
-    
-    platform_set_drvdata(pldev, master);
-    
-    kpspi = spi_master_get_devdata(master);
-    kpspi->master = master;
-    kpspi->dev = &pldev->dev;
-    
-    master->num_chipselect = 4;
-    if (pldev->id != -1) {
-        master->bus_num = pldev->id;
-    }
-    kpspi->pin_dir = 0;
-    
-    r = platform_get_resource(pldev, IORESOURCE_MEM, 0);
-    if (r = NULL) {
-        dev_err(&pldev->dev, "kp_spi_probe: Unable to get platform resources\n");
-        status = -ENODEV;
-        goto free_master;
-    }
-    
-    kpspi->phys = (unsigned long)ioremap_nocache(r->start, resource_size(r));
-    kpspi->base = (u64 __iomem *)kpspi->phys;
-    
-    status = spi_register_master(master);
-    if (status < 0) {
-        dev_err(&pldev->dev, "Unable to register SPI device\n");
-        goto free_master;
-    }
-    
-    /* register the slave boards */
-    #define NEW_SPI_DEVICE_FROM_BOARD_INFO_TABLE(table) \
-        for (i = 0 ; i < ARRAY_SIZE(table) ; i++) { \
-            spi_new_device(master, &(table[i])); \
-        }
-    
-    switch ((drvdata->card_id & 0xFFFF0000) >> 16){
-        case PCI_DEVICE_ID_DAKTRONICS_KADOKA_P2KR0:
-            NEW_SPI_DEVICE_FROM_BOARD_INFO_TABLE(p2kr0_board_info);
-            break;
-        default:
-            dev_err(&pldev->dev, "Unknown hardware, cant know what partition table to use!\n");
-            goto free_master;
-            break;
-    }
-    
-    return status;
-
- free_master:
-    spi_master_put(master);
-    return status;
+	struct kpc_core_device_platdata *drvdata;
+	struct spi_master *master;
+	struct kp_spi *kpspi;
+	struct resource *r;
+	int status = 0;
+	int i;
+
+	drvdata = pldev->dev.platform_data;
+	if (!drvdata){
+		dev_err(&pldev->dev, "kp_spi_probe: platform_data is NULL!\n");
+		return -ENODEV;
+	}
+
+	master = spi_alloc_master(&pldev->dev, sizeof(struct kp_spi));
+	if (master = NULL) {
+		dev_err(&pldev->dev, "kp_spi_probe: master allocation failed\n");
+		return -ENOMEM;
+	}
+
+	/* set up the spi functions */
+	master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
+	master->bits_per_word_mask = (unsigned int)SPI_BPW_RANGE_MASK(4, 32);
+	master->setup = kp_spi_setup;
+	master->transfer_one_message = kp_spi_transfer_one_message;
+	master->cleanup = kp_spi_cleanup;
+
+	platform_set_drvdata(pldev, master);
+
+	kpspi = spi_master_get_devdata(master);
+	kpspi->master = master;
+	kpspi->dev = &pldev->dev;
+
+	master->num_chipselect = 4;
+	if (pldev->id != -1) {
+		master->bus_num = pldev->id;
+	}
+	kpspi->pin_dir = 0;
+
+	r = platform_get_resource(pldev, IORESOURCE_MEM, 0);
+	if (r = NULL) {
+		dev_err(&pldev->dev, "kp_spi_probe: Unable to get platform resources\n");
+		status = -ENODEV;
+		goto free_master;
+	}
+
+	kpspi->phys = (unsigned long)ioremap_nocache(r->start, resource_size(r));
+	kpspi->base = (u64 __iomem *)kpspi->phys;
+
+	status = spi_register_master(master);
+	if (status < 0) {
+		dev_err(&pldev->dev, "Unable to register SPI device\n");
+		goto free_master;
+	}
+
+	/* register the slave boards */
+#define NEW_SPI_DEVICE_FROM_BOARD_INFO_TABLE(table) \
+	for (i = 0 ; i < ARRAY_SIZE(table) ; i++) { \
+		spi_new_device(master, &(table[i])); \
+	}
+
+	switch ((drvdata->card_id & 0xFFFF0000) >> 16){
+		case PCI_DEVICE_ID_DAKTRONICS_KADOKA_P2KR0:
+			NEW_SPI_DEVICE_FROM_BOARD_INFO_TABLE(p2kr0_board_info);
+			break;
+		default:
+			dev_err(&pldev->dev, "Unknown hardware, cant know what partition table to use!\n");
+			goto free_master;
+			break;
+	}
+
+	return status;
+
+free_master:
+	spi_master_put(master);
+	return status;
 }
 
-static int
+	static int
 kp_spi_remove(struct platform_device *pldev)
 {
-    struct spi_master * master = platform_get_drvdata(pldev);
-    spi_unregister_master(master);
-    return 0;
+	struct spi_master * master = platform_get_drvdata(pldev);
+	spi_unregister_master(master);
+	return 0;
 }
 
 
 static struct platform_driver kp_spi_driver = {
-    .driver = {
-        .name =     KP_DRIVER_NAME_SPI,
-    },
-    .probe =    kp_spi_probe,
-    .remove =   kp_spi_remove,
+	.driver = {
+		.name =     KP_DRIVER_NAME_SPI,
+	},
+	.probe =    kp_spi_probe,
+	.remove =   kp_spi_remove,
 };
 
 module_platform_driver(kp_spi_driver);
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH -next v3 1/2] staging: kpc2000: report error status to spi core
  2019-05-28  8:02     ` Mao Wenan
@ 2019-05-28  8:02       ` Mao Wenan
  -1 siblings, 0 replies; 20+ messages in thread
From: Mao Wenan @ 2019-05-28  7:54 UTC (permalink / raw)
  To: gregkh, jeremy
  Cc: thesven73, devel, linux-kernel, kernel-janitors, matt.sickler, Mao Wenan

There is an error condition that's not reported to
the spi core in kp_spi_transfer_one_message().
It should restore status value to m->status, and
return it in error path.

Signed-off-by: Mao Wenan <maowenan@huawei.com>
---
 drivers/staging/kpc2000/kpc2000_spi.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000_spi.c b/drivers/staging/kpc2000/kpc2000_spi.c
index 075ae4fafa7d..628a447642ad 100644
--- a/drivers/staging/kpc2000/kpc2000_spi.c
+++ b/drivers/staging/kpc2000/kpc2000_spi.c
@@ -374,7 +374,7 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
     list_for_each_entry(transfer, &m->transfers, transfer_list) {
         if (transfer->tx_buf = NULL && transfer->rx_buf = NULL && transfer->len) {
             status = -EINVAL;
-            break;
+            goto error;
         }
         
         /* transfer */
@@ -412,7 +412,7 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
             
             if (count != transfer->len) {
                 status = -EIO;
-                break;
+                goto error;
             }
         }
         
@@ -430,6 +430,10 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
     /* done work */
     spi_finalize_current_message(master);
     return 0;
+
+ error:
+    m->status = status;
+    return status;
 }
 
 static void
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH -next v3 0/2] cleanup for kpc2000_spi.c
  2019-05-25  8:13   ` [PATCH -next v2] staging: kpc2000: Remove set b =?UTF-8?q?ut=20not=20used=20vari Mao Wenan
@ 2019-05-28  8:02     ` Mao Wenan
  -1 siblings, 0 replies; 20+ messages in thread
From: Mao Wenan @ 2019-05-28  7:54 UTC (permalink / raw)
  To: gregkh, jeremy
  Cc: thesven73, devel, linux-kernel, kernel-janitors, matt.sickler, Mao Wenan

The error status should resotre to m->status in kp_spi_transfer_one_message(),
and many white spaces in kpc2000_spi.c. patch 1 is to fix the error path, and
patch 2 is to cleanup kpc2000_spi.c.

v1: remove set but not used variable 'status'.

v2: fix the subject tile.

v3: add another patch to fix the error condition path and do some clean work for kpc2000_spi.c.

Mao Wenan (2):
  staging: kpc2000: report error status to spi core
  staging: kpc2000: replace white spaces with tabs for kpc2000_spi.c

 drivers/staging/kpc2000/kpc2000_spi.c | 718 +++++++++++++-------------
 1 file changed, 361 insertions(+), 357 deletions(-)

-- 
2.20.1

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH -next v3 0/2] cleanup for kpc2000_spi.c
@ 2019-05-28  8:02     ` Mao Wenan
  0 siblings, 0 replies; 20+ messages in thread
From: Mao Wenan @ 2019-05-28  8:02 UTC (permalink / raw)
  To: gregkh, jeremy
  Cc: thesven73, devel, linux-kernel, kernel-janitors, matt.sickler, Mao Wenan

The error status should resotre to m->status in kp_spi_transfer_one_message(),
and many white spaces in kpc2000_spi.c. patch 1 is to fix the error path, and
patch 2 is to cleanup kpc2000_spi.c.

v1: remove set but not used variable 'status'.

v2: fix the subject tile.

v3: add another patch to fix the error condition path and do some clean work for kpc2000_spi.c.

Mao Wenan (2):
  staging: kpc2000: report error status to spi core
  staging: kpc2000: replace white spaces with tabs for kpc2000_spi.c

 drivers/staging/kpc2000/kpc2000_spi.c | 718 +++++++++++++-------------
 1 file changed, 361 insertions(+), 357 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH -next v3 1/2] staging: kpc2000: report error status to spi core
@ 2019-05-28  8:02       ` Mao Wenan
  0 siblings, 0 replies; 20+ messages in thread
From: Mao Wenan @ 2019-05-28  8:02 UTC (permalink / raw)
  To: gregkh, jeremy
  Cc: thesven73, devel, linux-kernel, kernel-janitors, matt.sickler, Mao Wenan

There is an error condition that's not reported to
the spi core in kp_spi_transfer_one_message().
It should restore status value to m->status, and
return it in error path.

Signed-off-by: Mao Wenan <maowenan@huawei.com>
---
 drivers/staging/kpc2000/kpc2000_spi.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000_spi.c b/drivers/staging/kpc2000/kpc2000_spi.c
index 075ae4fafa7d..628a447642ad 100644
--- a/drivers/staging/kpc2000/kpc2000_spi.c
+++ b/drivers/staging/kpc2000/kpc2000_spi.c
@@ -374,7 +374,7 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
     list_for_each_entry(transfer, &m->transfers, transfer_list) {
         if (transfer->tx_buf == NULL && transfer->rx_buf == NULL && transfer->len) {
             status = -EINVAL;
-            break;
+            goto error;
         }
         
         /* transfer */
@@ -412,7 +412,7 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
             
             if (count != transfer->len) {
                 status = -EIO;
-                break;
+                goto error;
             }
         }
         
@@ -430,6 +430,10 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
     /* done work */
     spi_finalize_current_message(master);
     return 0;
+
+ error:
+    m->status = status;
+    return status;
 }
 
 static void
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH -next v3 2/2] staging: kpc2000: replace white spaces with tabs for kpc2000_spi.c
@ 2019-05-28  8:02       ` Mao Wenan
  0 siblings, 0 replies; 20+ messages in thread
From: Mao Wenan @ 2019-05-28  8:02 UTC (permalink / raw)
  To: gregkh, jeremy
  Cc: thesven73, devel, linux-kernel, kernel-janitors, matt.sickler, Mao Wenan

There are multiple wrong formats in kpc2000_spi.c,
is time to do clean work for it.

Signed-off-by: Mao Wenan <maowenan@huawei.com>
---
 drivers/staging/kpc2000/kpc2000_spi.c | 722 +++++++++++++-------------
 1 file changed, 361 insertions(+), 361 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000_spi.c b/drivers/staging/kpc2000/kpc2000_spi.c
index 628a447642ad..9a23808ffaa1 100644
--- a/drivers/staging/kpc2000/kpc2000_spi.c
+++ b/drivers/staging/kpc2000/kpc2000_spi.c
@@ -113,59 +113,59 @@ struct kp_spi {
 
 
 struct kp_spi_controller_state {
-    void __iomem   *base;
-    unsigned long   phys;
-    unsigned char   chip_select;
-    int             word_len;
-    s64             conf_cache;
+	void __iomem   *base;
+	unsigned long   phys;
+	unsigned char   chip_select;
+	int             word_len;
+	s64             conf_cache;
 };
 
 
 union kp_spi_config {
-    /* use this to access individual elements */
-    struct __attribute__((packed)) spi_config_bitfield {
-        unsigned int pha       : 1; /* spim_clk Phase      */
-        unsigned int pol       : 1; /* spim_clk Polarity   */
-        unsigned int epol      : 1; /* spim_csx Polarity   */
-        unsigned int dpe       : 1; /* Transmission Enable */
-        unsigned int wl        : 5; /* Word Length         */
-        unsigned int           : 3;
-        unsigned int trm       : 2; /* TxRx Mode           */
-        unsigned int cs        : 4; /* Chip Select         */
-        unsigned int wcnt      : 7; /* Word Count          */
-        unsigned int ffen      : 1; /* FIFO Enable         */
-        unsigned int spi_en    : 1; /* SPI Enable          */
-        unsigned int           : 5;
-    } bitfield;
-    /* use this to grab the whole register */
-    u32 reg;
+	/* use this to access individual elements */
+	struct __attribute__((packed)) spi_config_bitfield {
+		unsigned int pha       : 1; /* spim_clk Phase      */
+		unsigned int pol       : 1; /* spim_clk Polarity   */
+		unsigned int epol      : 1; /* spim_csx Polarity   */
+		unsigned int dpe       : 1; /* Transmission Enable */
+		unsigned int wl        : 5; /* Word Length         */
+		unsigned int           : 3;
+		unsigned int trm       : 2; /* TxRx Mode           */
+		unsigned int cs        : 4; /* Chip Select         */
+		unsigned int wcnt      : 7; /* Word Count          */
+		unsigned int ffen      : 1; /* FIFO Enable         */
+		unsigned int spi_en    : 1; /* SPI Enable          */
+		unsigned int           : 5;
+	} bitfield;
+	/* use this to grab the whole register */
+	u32 reg;
 };
 
 
 
 union kp_spi_status {
-    struct __attribute__((packed)) spi_status_bitfield {
-        unsigned int rx    :  1; /* Rx Status       */
-        unsigned int tx    :  1; /* Tx Status       */
-        unsigned int eo    :  1; /* End of Transfer */
-        unsigned int       :  1;
-        unsigned int txffe :  1; /* Tx FIFO Empty   */
-        unsigned int txfff :  1; /* Tx FIFO Full    */
-        unsigned int rxffe :  1; /* Rx FIFO Empty   */
-        unsigned int rxfff :  1; /* Rx FIFO Full    */
-        unsigned int       : 24;
-    } bitfield;
-    u32 reg;
+	struct __attribute__((packed)) spi_status_bitfield {
+		unsigned int rx    :  1; /* Rx Status       */
+		unsigned int tx    :  1; /* Tx Status       */
+		unsigned int eo    :  1; /* End of Transfer */
+		unsigned int       :  1;
+		unsigned int txffe :  1; /* Tx FIFO Empty   */
+		unsigned int txfff :  1; /* Tx FIFO Full    */
+		unsigned int rxffe :  1; /* Rx FIFO Empty   */
+		unsigned int rxfff :  1; /* Rx FIFO Full    */
+		unsigned int       : 24;
+	} bitfield;
+	u32 reg;
 };
 
 
 
 union kp_spi_ffctrl {
-    struct __attribute__((packed)) spi_ffctrl_bitfield {
-        unsigned int ffstart :  1; /* FIFO Start */
-        unsigned int         : 31;
-    } bitfield;
-    u32 reg;
+	struct __attribute__((packed)) spi_ffctrl_bitfield {
+		unsigned int ffstart :  1; /* FIFO Start */
+		unsigned int         : 31;
+	} bitfield;
+	u32 reg;
 };
 
 
@@ -173,276 +173,276 @@ union kp_spi_ffctrl {
 /***************
  * SPI Helpers *
  ***************/
-static inline int
+	static inline int
 kp_spi_bytes_per_word(int word_len)
 {
-    if (word_len <= 8){
-        return 1;
-    }
-    else if (word_len <= 16) {
-        return 2;
-    }
-    else { /* word_len <= 32 */
-        return 4;
-    }
+	if (word_len <= 8){
+		return 1;
+	}
+	else if (word_len <= 16) {
+		return 2;
+	}
+	else { /* word_len <= 32 */
+		return 4;
+	}
 }
 
-static inline u64
+	static inline u64
 kp_spi_read_reg(struct kp_spi_controller_state *cs, int idx)
 {
-    u64 __iomem *addr = cs->base;
-    u64 val;
-
-    addr += idx;
-    if ((idx == KP_SPI_REG_CONFIG) && (cs->conf_cache >= 0)){
-        return cs->conf_cache;
-    }
-    val = readq((void*)addr);
-    return val;
+	u64 __iomem *addr = cs->base;
+	u64 val;
+
+	addr += idx;
+	if ((idx == KP_SPI_REG_CONFIG) && (cs->conf_cache >= 0)){
+		return cs->conf_cache;
+	}
+	val = readq((void*)addr);
+	return val;
 }
 
-static inline void
+	static inline void
 kp_spi_write_reg(struct kp_spi_controller_state *cs, int idx, u64 val)
 {
-    u64 __iomem *addr = cs->base;
-    addr += idx;
-    writeq(val, (void*)addr);
-    if (idx == KP_SPI_REG_CONFIG)
-        cs->conf_cache = val;
+	u64 __iomem *addr = cs->base;
+	addr += idx;
+	writeq(val, (void*)addr);
+	if (idx == KP_SPI_REG_CONFIG)
+		cs->conf_cache = val;
 }
 
-static int
+	static int
 kp_spi_wait_for_reg_bit(struct kp_spi_controller_state *cs, int idx, unsigned long bit)
 {
-    unsigned long timeout;
-    timeout = jiffies + msecs_to_jiffies(1000);
-    while (!(kp_spi_read_reg(cs, idx) & bit)) {
-        if (time_after(jiffies, timeout)) {
-            if (!(kp_spi_read_reg(cs, idx) & bit)) {
-                return -ETIMEDOUT;
-            } else {
-                return 0;
-            }
-        }
-        cpu_relax();
-    }
-    return 0;
+	unsigned long timeout;
+	timeout = jiffies + msecs_to_jiffies(1000);
+	while (!(kp_spi_read_reg(cs, idx) & bit)) {
+		if (time_after(jiffies, timeout)) {
+			if (!(kp_spi_read_reg(cs, idx) & bit)) {
+				return -ETIMEDOUT;
+			} else {
+				return 0;
+			}
+		}
+		cpu_relax();
+	}
+	return 0;
 }
 
-static unsigned
+	static unsigned
 kp_spi_txrx_pio(struct spi_device *spidev, struct spi_transfer *transfer)
 {
-    struct kp_spi_controller_state *cs = spidev->controller_state;
-    unsigned int count = transfer->len;
-    unsigned int c = count;
-    
-    int i;
-    u8 *rx       = transfer->rx_buf;
-    const u8 *tx = transfer->tx_buf;
-    int processed = 0;
-    
-    if (tx) {
-        for (i = 0 ; i < c ; i++) {
-            char val = *tx++;
-            
-            if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_TXS) < 0) {
-                goto out;
-            }
-            
-            kp_spi_write_reg(cs, KP_SPI_REG_TXDATA, val);
-            processed++;
-        }
-    }
-    else if(rx) {
-        for (i = 0 ; i < c ; i++) {
-            char test=0;
-            
-            kp_spi_write_reg(cs, KP_SPI_REG_TXDATA, 0x00);
-            
-            if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_RXS) < 0) {
-                goto out;
-            }
-            
-            test = kp_spi_read_reg(cs, KP_SPI_REG_RXDATA);
-            *rx++ = test;
-            processed++;
-        }
-    }
-    
-    if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_EOT) < 0) {
-        //TODO: Figure out how to abort transaction??  This has never happened in practice though...
-    }
-    
- out:
-    return processed;
+	struct kp_spi_controller_state *cs = spidev->controller_state;
+	unsigned int count = transfer->len;
+	unsigned int c = count;
+
+	int i;
+	u8 *rx       = transfer->rx_buf;
+	const u8 *tx = transfer->tx_buf;
+	int processed = 0;
+
+	if (tx) {
+		for (i = 0 ; i < c ; i++) {
+			char val = *tx++;
+
+			if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_TXS) < 0) {
+				goto out;
+			}
+
+			kp_spi_write_reg(cs, KP_SPI_REG_TXDATA, val);
+			processed++;
+		}
+	}
+	else if(rx) {
+		for (i = 0 ; i < c ; i++) {
+			char test=0;
+
+			kp_spi_write_reg(cs, KP_SPI_REG_TXDATA, 0x00);
+
+			if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_RXS) < 0) {
+				goto out;
+			}
+
+			test = kp_spi_read_reg(cs, KP_SPI_REG_RXDATA);
+			*rx++ = test;
+			processed++;
+		}
+	}
+
+	if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_EOT) < 0) {
+		//TODO: Figure out how to abort transaction??  This has never happened in practice though...
+	}
+
+out:
+	return processed;
 }
 
 /*****************
  * SPI Functions *
  *****************/
-static int
+	static int
 kp_spi_setup(struct spi_device *spidev)
 {
-    union kp_spi_config sc;
-    struct kp_spi *kpspi = spi_master_get_devdata(spidev->master);
-    struct kp_spi_controller_state *cs;
-    
-    /* setup controller state */
-    cs = spidev->controller_state;
-    if (!cs) {
-        cs = kzalloc(sizeof(*cs), GFP_KERNEL);
-        if(!cs) {
-            return -ENOMEM;
-        }
-        cs->base = kpspi->base;
-        cs->phys = kpspi->phys;
-        cs->chip_select = spidev->chip_select;
-        cs->word_len = spidev->bits_per_word;
-        cs->conf_cache = -1;
-        spidev->controller_state = cs;
-    }
-    
-    /* set config register */
-    sc.bitfield.wl = spidev->bits_per_word - 1;
-    sc.bitfield.cs = spidev->chip_select;
-    sc.bitfield.spi_en = 0;
-    sc.bitfield.trm = 0;
-    sc.bitfield.ffen = 0;
-    kp_spi_write_reg(spidev->controller_state, KP_SPI_REG_CONFIG, sc.reg);
-    return 0;
+	union kp_spi_config sc;
+	struct kp_spi *kpspi = spi_master_get_devdata(spidev->master);
+	struct kp_spi_controller_state *cs;
+
+	/* setup controller state */
+	cs = spidev->controller_state;
+	if (!cs) {
+		cs = kzalloc(sizeof(*cs), GFP_KERNEL);
+		if(!cs) {
+			return -ENOMEM;
+		}
+		cs->base = kpspi->base;
+		cs->phys = kpspi->phys;
+		cs->chip_select = spidev->chip_select;
+		cs->word_len = spidev->bits_per_word;
+		cs->conf_cache = -1;
+		spidev->controller_state = cs;
+	}
+
+	/* set config register */
+	sc.bitfield.wl = spidev->bits_per_word - 1;
+	sc.bitfield.cs = spidev->chip_select;
+	sc.bitfield.spi_en = 0;
+	sc.bitfield.trm = 0;
+	sc.bitfield.ffen = 0;
+	kp_spi_write_reg(spidev->controller_state, KP_SPI_REG_CONFIG, sc.reg);
+	return 0;
 }
 
-static int
+	static int
 kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m)
 {
-    struct kp_spi_controller_state *cs;
-    struct spi_device   *spidev;
-    struct kp_spi       *kpspi;
-    struct spi_transfer *transfer;
-    union kp_spi_config sc;
-    int status = 0;
-    
-    spidev = m->spi;
-    kpspi = spi_master_get_devdata(master);
-    m->actual_length = 0;
-    m->status = 0;
-    
-    cs = spidev->controller_state;
-    
-    /* reject invalid messages and transfers */
-    if (list_empty(&m->transfers)) {
-        return -EINVAL;
-    }
-    
-    /* validate input */
-    list_for_each_entry(transfer, &m->transfers, transfer_list) {
-        const void *tx_buf = transfer->tx_buf;
-        void       *rx_buf = transfer->rx_buf;
-        unsigned    len = transfer->len;
-        
-        if (transfer->speed_hz > KP_SPI_CLK || (len && !(rx_buf || tx_buf))) {
-            dev_dbg(kpspi->dev, "  transfer: %d Hz, %d %s%s, %d bpw\n",
-                    transfer->speed_hz,
-                    len,
-                    tx_buf ? "tx" : "",
-                    rx_buf ? "rx" : "",
-                    transfer->bits_per_word);
-            dev_dbg(kpspi->dev, "  transfer -EINVAL\n");
-            return -EINVAL;
-        }
-        if (transfer->speed_hz && (transfer->speed_hz < (KP_SPI_CLK >> 15))) {
-            dev_dbg(kpspi->dev, "speed_hz %d below minimum %d Hz\n",
-                    transfer->speed_hz,
-                    KP_SPI_CLK >> 15);
-            dev_dbg(kpspi->dev, "  speed_hz -EINVAL\n");
-            return -EINVAL;
-        }
-    }
-    
-    /* assert chip select to start the sequence*/
-    sc.reg = kp_spi_read_reg(cs, KP_SPI_REG_CONFIG);
-    sc.bitfield.spi_en = 1;
-    kp_spi_write_reg(cs, KP_SPI_REG_CONFIG, sc.reg);
-    
-    /* work */
-    if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_EOT) < 0) {
-        dev_info(kpspi->dev, "EOT timed out\n");
-        goto out;
-    }
-    
-    /* do the transfers for this message */
-    list_for_each_entry(transfer, &m->transfers, transfer_list) {
-        if (transfer->tx_buf == NULL && transfer->rx_buf == NULL && transfer->len) {
-            status = -EINVAL;
-            goto error;
-        }
-        
-        /* transfer */
-        if (transfer->len) {
-            unsigned int word_len = spidev->bits_per_word;
-            unsigned count;
-            
-            /* set up the transfer... */
-            sc.reg = kp_spi_read_reg(cs, KP_SPI_REG_CONFIG);
-            
-            /* ...direction */
-            if (transfer->tx_buf) {
-                sc.bitfield.trm = KP_SPI_REG_CONFIG_TRM_TX;
-            }
-            else if (transfer->rx_buf) {
-                sc.bitfield.trm = KP_SPI_REG_CONFIG_TRM_RX;
-            }
-            
-            /* ...word length */
-            if (transfer->bits_per_word) {
-                word_len = transfer->bits_per_word;
-            }
-            cs->word_len = word_len;
-            sc.bitfield.wl = word_len-1;
-            
-            /* ...chip select */
-            sc.bitfield.cs = spidev->chip_select;
-            
-            /* ...and write the new settings */
-            kp_spi_write_reg(cs, KP_SPI_REG_CONFIG, sc.reg);
-            
-            /* do the transfer */
-            count = kp_spi_txrx_pio(spidev, transfer);
-            m->actual_length += count;
-            
-            if (count != transfer->len) {
-                status = -EIO;
-                goto error;
-            }
-        }
-        
-        if (transfer->delay_usecs) {
-            udelay(transfer->delay_usecs);
-        }
-    }
-    
-    /* de-assert chip select to end the sequence */
-    sc.reg = kp_spi_read_reg(cs, KP_SPI_REG_CONFIG);
-    sc.bitfield.spi_en = 0;
-    kp_spi_write_reg(cs, KP_SPI_REG_CONFIG, sc.reg);
-    
- out:
-    /* done work */
-    spi_finalize_current_message(master);
-    return 0;
-
- error:
-    m->status = status;
-    return status;
+	struct kp_spi_controller_state *cs;
+	struct spi_device   *spidev;
+	struct kp_spi       *kpspi;
+	struct spi_transfer *transfer;
+	union kp_spi_config sc;
+	int status = 0;
+
+	spidev = m->spi;
+	kpspi = spi_master_get_devdata(master);
+	m->actual_length = 0;
+	m->status = 0;
+
+	cs = spidev->controller_state;
+
+	/* reject invalid messages and transfers */
+	if (list_empty(&m->transfers)) {
+		return -EINVAL;
+	}
+
+	/* validate input */
+	list_for_each_entry(transfer, &m->transfers, transfer_list) {
+		const void *tx_buf = transfer->tx_buf;
+		void       *rx_buf = transfer->rx_buf;
+		unsigned    len = transfer->len;
+
+		if (transfer->speed_hz > KP_SPI_CLK || (len && !(rx_buf || tx_buf))) {
+			dev_dbg(kpspi->dev, "  transfer: %d Hz, %d %s%s, %d bpw\n",
+					transfer->speed_hz,
+					len,
+					tx_buf ? "tx" : "",
+					rx_buf ? "rx" : "",
+					transfer->bits_per_word);
+			dev_dbg(kpspi->dev, "  transfer -EINVAL\n");
+			return -EINVAL;
+		}
+		if (transfer->speed_hz && (transfer->speed_hz < (KP_SPI_CLK >> 15))) {
+			dev_dbg(kpspi->dev, "speed_hz %d below minimum %d Hz\n",
+					transfer->speed_hz,
+					KP_SPI_CLK >> 15);
+			dev_dbg(kpspi->dev, "  speed_hz -EINVAL\n");
+			return -EINVAL;
+		}
+	}
+
+	/* assert chip select to start the sequence*/
+	sc.reg = kp_spi_read_reg(cs, KP_SPI_REG_CONFIG);
+	sc.bitfield.spi_en = 1;
+	kp_spi_write_reg(cs, KP_SPI_REG_CONFIG, sc.reg);
+
+	/* work */
+	if (kp_spi_wait_for_reg_bit(cs, KP_SPI_REG_STATUS, KP_SPI_REG_STATUS_EOT) < 0) {
+		dev_info(kpspi->dev, "EOT timed out\n");
+		goto out;
+	}
+
+	/* do the transfers for this message */
+	list_for_each_entry(transfer, &m->transfers, transfer_list) {
+		if (transfer->tx_buf == NULL && transfer->rx_buf == NULL && transfer->len) {
+			status = -EINVAL;
+			goto error;
+		}
+
+		/* transfer */
+		if (transfer->len) {
+			unsigned int word_len = spidev->bits_per_word;
+			unsigned count;
+
+			/* set up the transfer... */
+			sc.reg = kp_spi_read_reg(cs, KP_SPI_REG_CONFIG);
+
+			/* ...direction */
+			if (transfer->tx_buf) {
+				sc.bitfield.trm = KP_SPI_REG_CONFIG_TRM_TX;
+			}
+			else if (transfer->rx_buf) {
+				sc.bitfield.trm = KP_SPI_REG_CONFIG_TRM_RX;
+			}
+
+			/* ...word length */
+			if (transfer->bits_per_word) {
+				word_len = transfer->bits_per_word;
+			}
+			cs->word_len = word_len;
+			sc.bitfield.wl = word_len-1;
+
+			/* ...chip select */
+			sc.bitfield.cs = spidev->chip_select;
+
+			/* ...and write the new settings */
+			kp_spi_write_reg(cs, KP_SPI_REG_CONFIG, sc.reg);
+
+			/* do the transfer */
+			count = kp_spi_txrx_pio(spidev, transfer);
+			m->actual_length += count;
+
+			if (count != transfer->len) {
+				status = -EIO;
+				goto error;
+			}
+		}
+
+		if (transfer->delay_usecs) {
+			udelay(transfer->delay_usecs);
+		}
+	}
+
+	/* de-assert chip select to end the sequence */
+	sc.reg = kp_spi_read_reg(cs, KP_SPI_REG_CONFIG);
+	sc.bitfield.spi_en = 0;
+	kp_spi_write_reg(cs, KP_SPI_REG_CONFIG, sc.reg);
+
+out:
+	/* done work */
+	spi_finalize_current_message(master);
+	return 0;
+
+error:
+	m->status = status;
+	return status;
 }
 
-static void
+	static void
 kp_spi_cleanup(struct spi_device *spidev)
 {
-    struct kp_spi_controller_state *cs = spidev->controller_state;
-    if (cs) {
-        kfree(cs);
-    }
+	struct kp_spi_controller_state *cs = spidev->controller_state;
+	if (cs) {
+		kfree(cs);
+	}
 }
 
 
@@ -450,101 +450,101 @@ kp_spi_cleanup(struct spi_device *spidev)
 /******************
  * Probe / Remove *
  ******************/
-static int
+	static int
 kp_spi_probe(struct platform_device *pldev)
 {
-    struct kpc_core_device_platdata *drvdata;
-    struct spi_master *master;
-    struct kp_spi *kpspi;
-    struct resource *r;
-    int status = 0;
-    int i;
-
-    drvdata = pldev->dev.platform_data;
-    if (!drvdata){
-        dev_err(&pldev->dev, "kp_spi_probe: platform_data is NULL!\n");
-        return -ENODEV;
-    }
-    
-    master = spi_alloc_master(&pldev->dev, sizeof(struct kp_spi));
-    if (master == NULL) {
-        dev_err(&pldev->dev, "kp_spi_probe: master allocation failed\n");
-        return -ENOMEM;
-    }
-    
-    /* set up the spi functions */
-    master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
-    master->bits_per_word_mask = (unsigned int)SPI_BPW_RANGE_MASK(4, 32);
-    master->setup = kp_spi_setup;
-    master->transfer_one_message = kp_spi_transfer_one_message;
-    master->cleanup = kp_spi_cleanup;
-    
-    platform_set_drvdata(pldev, master);
-    
-    kpspi = spi_master_get_devdata(master);
-    kpspi->master = master;
-    kpspi->dev = &pldev->dev;
-    
-    master->num_chipselect = 4;
-    if (pldev->id != -1) {
-        master->bus_num = pldev->id;
-    }
-    kpspi->pin_dir = 0;
-    
-    r = platform_get_resource(pldev, IORESOURCE_MEM, 0);
-    if (r == NULL) {
-        dev_err(&pldev->dev, "kp_spi_probe: Unable to get platform resources\n");
-        status = -ENODEV;
-        goto free_master;
-    }
-    
-    kpspi->phys = (unsigned long)ioremap_nocache(r->start, resource_size(r));
-    kpspi->base = (u64 __iomem *)kpspi->phys;
-    
-    status = spi_register_master(master);
-    if (status < 0) {
-        dev_err(&pldev->dev, "Unable to register SPI device\n");
-        goto free_master;
-    }
-    
-    /* register the slave boards */
-    #define NEW_SPI_DEVICE_FROM_BOARD_INFO_TABLE(table) \
-        for (i = 0 ; i < ARRAY_SIZE(table) ; i++) { \
-            spi_new_device(master, &(table[i])); \
-        }
-    
-    switch ((drvdata->card_id & 0xFFFF0000) >> 16){
-        case PCI_DEVICE_ID_DAKTRONICS_KADOKA_P2KR0:
-            NEW_SPI_DEVICE_FROM_BOARD_INFO_TABLE(p2kr0_board_info);
-            break;
-        default:
-            dev_err(&pldev->dev, "Unknown hardware, cant know what partition table to use!\n");
-            goto free_master;
-            break;
-    }
-    
-    return status;
-
- free_master:
-    spi_master_put(master);
-    return status;
+	struct kpc_core_device_platdata *drvdata;
+	struct spi_master *master;
+	struct kp_spi *kpspi;
+	struct resource *r;
+	int status = 0;
+	int i;
+
+	drvdata = pldev->dev.platform_data;
+	if (!drvdata){
+		dev_err(&pldev->dev, "kp_spi_probe: platform_data is NULL!\n");
+		return -ENODEV;
+	}
+
+	master = spi_alloc_master(&pldev->dev, sizeof(struct kp_spi));
+	if (master == NULL) {
+		dev_err(&pldev->dev, "kp_spi_probe: master allocation failed\n");
+		return -ENOMEM;
+	}
+
+	/* set up the spi functions */
+	master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
+	master->bits_per_word_mask = (unsigned int)SPI_BPW_RANGE_MASK(4, 32);
+	master->setup = kp_spi_setup;
+	master->transfer_one_message = kp_spi_transfer_one_message;
+	master->cleanup = kp_spi_cleanup;
+
+	platform_set_drvdata(pldev, master);
+
+	kpspi = spi_master_get_devdata(master);
+	kpspi->master = master;
+	kpspi->dev = &pldev->dev;
+
+	master->num_chipselect = 4;
+	if (pldev->id != -1) {
+		master->bus_num = pldev->id;
+	}
+	kpspi->pin_dir = 0;
+
+	r = platform_get_resource(pldev, IORESOURCE_MEM, 0);
+	if (r == NULL) {
+		dev_err(&pldev->dev, "kp_spi_probe: Unable to get platform resources\n");
+		status = -ENODEV;
+		goto free_master;
+	}
+
+	kpspi->phys = (unsigned long)ioremap_nocache(r->start, resource_size(r));
+	kpspi->base = (u64 __iomem *)kpspi->phys;
+
+	status = spi_register_master(master);
+	if (status < 0) {
+		dev_err(&pldev->dev, "Unable to register SPI device\n");
+		goto free_master;
+	}
+
+	/* register the slave boards */
+#define NEW_SPI_DEVICE_FROM_BOARD_INFO_TABLE(table) \
+	for (i = 0 ; i < ARRAY_SIZE(table) ; i++) { \
+		spi_new_device(master, &(table[i])); \
+	}
+
+	switch ((drvdata->card_id & 0xFFFF0000) >> 16){
+		case PCI_DEVICE_ID_DAKTRONICS_KADOKA_P2KR0:
+			NEW_SPI_DEVICE_FROM_BOARD_INFO_TABLE(p2kr0_board_info);
+			break;
+		default:
+			dev_err(&pldev->dev, "Unknown hardware, cant know what partition table to use!\n");
+			goto free_master;
+			break;
+	}
+
+	return status;
+
+free_master:
+	spi_master_put(master);
+	return status;
 }
 
-static int
+	static int
 kp_spi_remove(struct platform_device *pldev)
 {
-    struct spi_master * master = platform_get_drvdata(pldev);
-    spi_unregister_master(master);
-    return 0;
+	struct spi_master * master = platform_get_drvdata(pldev);
+	spi_unregister_master(master);
+	return 0;
 }
 
 
 static struct platform_driver kp_spi_driver = {
-    .driver = {
-        .name =     KP_DRIVER_NAME_SPI,
-    },
-    .probe =    kp_spi_probe,
-    .remove =   kp_spi_remove,
+	.driver = {
+		.name =     KP_DRIVER_NAME_SPI,
+	},
+	.probe =    kp_spi_probe,
+	.remove =   kp_spi_remove,
 };
 
 module_platform_driver(kp_spi_driver);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2019-05-28  7:54 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-25  4:26 [PATCH net] staging: Remove set but not used variable ‘status’ Mao Wenan
2019-05-25  4:26 ` [PATCH net] staging: Remove set but not used =?UTF-8?q?=20variable=20=E2=80=98 Mao Wenan
2019-05-25  5:01 ` [PATCH net] staging: Remove set but not used variable ‘status’ Greg KH
2019-05-25  5:01   ` [PATCH net] staging: Remove =?utf-8?Q?set_but_not_used_variable_=E2=80=98status=E2= Greg KH
2019-05-25  6:39   ` [PATCH net] staging: Remove set but not used variable ‘status’ maowenan
2019-05-25  6:39     ` [PATCH net] staging: Remove set but not used variable =?UTF-8?B?IOKAmHN0YXR1c+KAmQ== maowenan
2019-05-25  8:13 ` [PATCH -next v2] staging: kpc2000: Remove set but not used variable ‘status’ Mao Wenan
2019-05-25  8:13   ` [PATCH -next v2] staging: kpc2000: Remove set b =?UTF-8?q?ut=20not=20used=20vari Mao Wenan
2019-05-28  2:09   ` [PATCH -next v2] staging: kpc2000: Remove set but not used variable ‘status’ maowenan
2019-05-28  2:09     ` [PATCH -next v2] staging: kpc2000: Remove set but not =?UTF-8?B?IHVzZWQgdmFyaWFibGUg maowenan
2019-05-28  7:54   ` [PATCH -next v3 0/2] cleanup for kpc2000_spi.c Mao Wenan
2019-05-28  8:02     ` Mao Wenan
2019-05-28  7:54     ` [PATCH -next v3 2/2] staging: kpc2000: replace white spaces with tabs " Mao Wenan
2019-05-28  8:02       ` Mao Wenan
2019-05-28  7:54     ` [PATCH -next v3 1/2] staging: kpc2000: report error status to spi core Mao Wenan
2019-05-28  8:02       ` Mao Wenan
2019-05-25 12:59 ` [PATCH net] staging: Remove set but not used variable ‘status’ Sven Van Asbroeck
2019-05-25 12:59   ` [PATCH net] staging: Remove set but not used var =?UTF-8?Q?iable_=E2=80=98st Sven Van Asbroeck
2019-05-27  2:33   ` [PATCH net] staging: Remove set but not used variable ‘status’ maowenan
2019-05-27  2:33     ` [PATCH net] staging: Remove set but not used variable =?UTF-8?B?IOKAmHN0YXR1c+KAmQ== maowenan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.