* [PATCH v3] pata_artop: use *switch* in artop_init_one()
@ 2022-02-04 19:09 Sergey Shtylyov
2022-02-04 23:39 ` Damien Le Moal
0 siblings, 1 reply; 3+ messages in thread
From: Sergey Shtylyov @ 2022-02-04 19:09 UTC (permalink / raw)
To: Damien Le Moal, linux-ide
This driver uses a string of the *if* statements where a *switch* statement
fits better...
Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
---
This patch is against the 'for-next' branch of Damien Le Moal's 'libata.git'
repo.
Changes in version 3:
- fixed up the patch subject.
Changes in version 2:
- updated #define DRV_VERSION.
drivers/ata/pata_artop.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
Index: libata/drivers/ata/pata_artop.c
===================================================================
--- libata.orig/drivers/ata/pata_artop.c
+++ libata/drivers/ata/pata_artop.c
@@ -28,7 +28,7 @@
#include <linux/ata.h>
#define DRV_NAME "pata_artop"
-#define DRV_VERSION "0.4.6"
+#define DRV_VERSION "0.4.7"
/*
* The ARTOP has 33 Mhz and "over clocked" timing tables. Until we
@@ -394,16 +394,22 @@ static int artop_init_one (struct pci_de
if (rc)
return rc;
- if (id->driver_data == 0) /* 6210 variant */
+ switch (id->driver_data) {
+ case 0: /* 6210 variant */
ppi[0] = &info_6210;
- else if (id->driver_data == 1) /* 6260 */
+ break;
+ case 1: /* 6260 */
ppi[0] = &info_626x;
- else if (id->driver_data == 2) { /* 6280 or 6280 + fast */
- unsigned long io = pci_resource_start(pdev, 4);
-
- ppi[0] = &info_628x;
- if (inb(io) & 0x10)
- ppi[0] = &info_628x_fast;
+ break;
+ case 2: /* 6280 or 6280 + fast */
+ {
+ unsigned long io = pci_resource_start(pdev, 4);
+
+ ppi[0] = &info_628x;
+ if (inb(io) & 0x10)
+ ppi[0] = &info_628x_fast;
+ }
+ break;
}
BUG_ON(ppi[0] == NULL);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] pata_artop: use *switch* in artop_init_one()
2022-02-04 19:09 [PATCH v3] pata_artop: use *switch* in artop_init_one() Sergey Shtylyov
@ 2022-02-04 23:39 ` Damien Le Moal
2022-02-05 10:36 ` Sergey Shtylyov
0 siblings, 1 reply; 3+ messages in thread
From: Damien Le Moal @ 2022-02-04 23:39 UTC (permalink / raw)
To: Sergey Shtylyov, linux-ide
On 2/5/22 04:09, Sergey Shtylyov wrote:
> This driver uses a string of the *if* statements where a *switch* statement
> fits better...
>
> Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
>
> ---
> This patch is against the 'for-next' branch of Damien Le Moal's 'libata.git'
> repo.
>
> Changes in version 3:
> - fixed up the patch subject.
>
> Changes in version 2:
> - updated #define DRV_VERSION.
>
> drivers/ata/pata_artop.c | 24 +++++++++++++++---------
> 1 file changed, 15 insertions(+), 9 deletions(-)
>
> Index: libata/drivers/ata/pata_artop.c
> ===================================================================
> --- libata.orig/drivers/ata/pata_artop.c
> +++ libata/drivers/ata/pata_artop.c
> @@ -28,7 +28,7 @@
> #include <linux/ata.h>
>
> #define DRV_NAME "pata_artop"
> -#define DRV_VERSION "0.4.6"
> +#define DRV_VERSION "0.4.7"
>
> /*
> * The ARTOP has 33 Mhz and "over clocked" timing tables. Until we
> @@ -394,16 +394,22 @@ static int artop_init_one (struct pci_de
> if (rc)
> return rc;
>
> - if (id->driver_data == 0) /* 6210 variant */
> + switch (id->driver_data) {
> + case 0: /* 6210 variant */
> ppi[0] = &info_6210;
> - else if (id->driver_data == 1) /* 6260 */
> + break;
> + case 1: /* 6260 */
> ppi[0] = &info_626x;
> - else if (id->driver_data == 2) { /* 6280 or 6280 + fast */
> - unsigned long io = pci_resource_start(pdev, 4);
> -
> - ppi[0] = &info_628x;
> - if (inb(io) & 0x10)
> - ppi[0] = &info_628x_fast;
> + break;
> + case 2: /* 6280 or 6280 + fast */
> + {
> + unsigned long io = pci_resource_start(pdev, 4);
> +
> + ppi[0] = &info_628x;
> + if (inb(io) & 0x10)
> + ppi[0] = &info_628x_fast;
> + }
Do you really need the local variable ?
I would make this:
if (pci_resource_start(pdev, 4) & 0x10)
ppi[0] = &info_628x_fast;
else
ppi[0] = &info_628x;
simpler :)
> + break;
> }
>
> BUG_ON(ppi[0] == NULL);
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] pata_artop: use *switch* in artop_init_one()
2022-02-04 23:39 ` Damien Le Moal
@ 2022-02-05 10:36 ` Sergey Shtylyov
0 siblings, 0 replies; 3+ messages in thread
From: Sergey Shtylyov @ 2022-02-05 10:36 UTC (permalink / raw)
To: Damien Le Moal, linux-ide
On 2/5/22 2:39 AM, Damien Le Moal wrote:
>> This driver uses a string of the *if* statements where a *switch* statement
>> fits better...
>>
>> Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
>>
>> ---
>> This patch is against the 'for-next' branch of Damien Le Moal's 'libata.git'
>> repo.
>>
>> Changes in version 3:
>> - fixed up the patch subject.
>>
>> Changes in version 2:
>> - updated #define DRV_VERSION.
>>
>> drivers/ata/pata_artop.c | 24 +++++++++++++++---------
>> 1 file changed, 15 insertions(+), 9 deletions(-)
>>
>> Index: libata/drivers/ata/pata_artop.c
>> ===================================================================
>> --- libata.orig/drivers/ata/pata_artop.c
>> +++ libata/drivers/ata/pata_artop.c
>> @@ -28,7 +28,7 @@
>> #include <linux/ata.h>
>>
>> #define DRV_NAME "pata_artop"
>> -#define DRV_VERSION "0.4.6"
>> +#define DRV_VERSION "0.4.7"
>>
>> /*
>> * The ARTOP has 33 Mhz and "over clocked" timing tables. Until we
>> @@ -394,16 +394,22 @@ static int artop_init_one (struct pci_de
>> if (rc)
>> return rc;
>>
>> - if (id->driver_data == 0) /* 6210 variant */
>> + switch (id->driver_data) {
>> + case 0: /* 6210 variant */
>> ppi[0] = &info_6210;
>> - else if (id->driver_data == 1) /* 6260 */
>> + break;
>> + case 1: /* 6260 */
>> ppi[0] = &info_626x;
>> - else if (id->driver_data == 2) { /* 6280 or 6280 + fast */
>> - unsigned long io = pci_resource_start(pdev, 4);
>> -
>> - ppi[0] = &info_628x;
>> - if (inb(io) & 0x10)
>> - ppi[0] = &info_628x_fast;
>> + break;
>> + case 2: /* 6280 or 6280 + fast */
>> + {
>> + unsigned long io = pci_resource_start(pdev, 4);
>> +
>> + ppi[0] = &info_628x;
>> + if (inb(io) & 0x10)
>> + ppi[0] = &info_628x_fast;
>> + }
>
>
> Do you really need the local variable ?
> I would make this:
>
> if (pci_resource_start(pdev, 4) & 0x10)
> ppi[0] = &info_628x_fast;
> else
> ppi[0] = &info_628x;
>
> simpler :)
Yeah! :-)
But a matter of another patch, I think...
[...]
MBR, Sergey
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-05 10:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-04 19:09 [PATCH v3] pata_artop: use *switch* in artop_init_one() Sergey Shtylyov
2022-02-04 23:39 ` Damien Le Moal
2022-02-05 10:36 ` Sergey Shtylyov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox