Linux ATA/IDE development
 help / color / mirror / Atom feed
* [PATCH 2/2] libata-scsi: better style in ata_msense_caching()
       [not found] <20160707014334.1031-1-me>
@ 2016-07-07  1:43 ` tom.ty89
  2016-07-07 10:55   ` Sergei Shtylyov
  0 siblings, 1 reply; 4+ messages in thread
From: tom.ty89 @ 2016-07-07  1:43 UTC (permalink / raw)
  To: tj; +Cc: linux-ide, linux-scsi, Tom Yan

From: Tom Yan <tom.ty89@gmail.com>

Signed-off-by: Tom Yan <tom.ty89@gmail.com>

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index bfec66f..e3f5751 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -2424,10 +2424,12 @@ static void modecpy(u8 *dest, const u8 *src, int n, bool changeable)
 static unsigned int ata_msense_caching(u16 *id, u8 *buf, bool changeable)
 {
 	modecpy(buf, def_cache_mpage, sizeof(def_cache_mpage), changeable);
-	if (changeable || ata_id_wcache_enabled(id))
-		buf[2] |= (1 << 2);	/* write cache enable */
-	if (!changeable && !ata_id_rahead_enabled(id))
-		buf[12] |= (1 << 5);	/* disable read ahead */
+	if (changeable)
+		buf[2] |= (1 << 2); /* ata_mselect_caching() */
+	else {
+		buf[2] |= (ata_id_wcache_enabled(id) << 2);	/* write cache enable */
+		buf[12] |= (!ata_id_rahead_enabled(id) << 5);	/* disable read ahead */
+	}
 	return sizeof(def_cache_mpage);
 }
 
-- 
2.9.0


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

* Re: [PATCH 2/2] libata-scsi: better style in ata_msense_caching()
  2016-07-07  1:43 ` [PATCH 2/2] libata-scsi: better style in ata_msense_caching() tom.ty89
@ 2016-07-07 10:55   ` Sergei Shtylyov
  2016-07-07 12:44     ` Tom Yan
  0 siblings, 1 reply; 4+ messages in thread
From: Sergei Shtylyov @ 2016-07-07 10:55 UTC (permalink / raw)
  To: tom.ty89, tj; +Cc: linux-ide, linux-scsi

On 7/7/2016 4:43 AM, tom.ty89@gmail.com wrote:

> From: Tom Yan <tom.ty89@gmail.com>
>
> Signed-off-by: Tom Yan <tom.ty89@gmail.com>
>
> diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
> index bfec66f..e3f5751 100644
> --- a/drivers/ata/libata-scsi.c
> +++ b/drivers/ata/libata-scsi.c
> @@ -2424,10 +2424,12 @@ static void modecpy(u8 *dest, const u8 *src, int n, bool changeable)
>  static unsigned int ata_msense_caching(u16 *id, u8 *buf, bool changeable)
>  {
>  	modecpy(buf, def_cache_mpage, sizeof(def_cache_mpage), changeable);
> -	if (changeable || ata_id_wcache_enabled(id))
> -		buf[2] |= (1 << 2);	/* write cache enable */
> -	if (!changeable && !ata_id_rahead_enabled(id))
> -		buf[12] |= (1 << 5);	/* disable read ahead */
> +	if (changeable)
> +		buf[2] |= (1 << 2); /* ata_mselect_caching() */

     Parens not really needed.

> +	else {

    CodingStyle: {} should be used in all branches if used in at least one.

> +		buf[2] |= (ata_id_wcache_enabled(id) << 2);	/* write cache enable */
> +		buf[12] |= (!ata_id_rahead_enabled(id) << 5);	/* disable read ahead */

    Outer parens not needed.

> +	}
>  	return sizeof(def_cache_mpage);
>  }
>

MBR, Sergei


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

* Re: [PATCH 2/2] libata-scsi: better style in ata_msense_caching()
  2016-07-07 10:55   ` Sergei Shtylyov
@ 2016-07-07 12:44     ` Tom Yan
  2016-07-07 13:00       ` Sergei Shtylyov
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Yan @ 2016-07-07 12:44 UTC (permalink / raw)
  To: Sergei Shtylyov; +Cc: Tejun Heo, linux-ide, linux-scsi

Sorry I am a bit new in this. Does that mean I should also use {} for
the if clause even it has only one line of statement, because I
(needed to) use that for the else clause? So it should be like:

if ... {
    ...
} else {
    ...
    ...
}

On 7 July 2016 at 18:55, Sergei Shtylyov
<sergei.shtylyov@cogentembedded.com> wrote:
>
>    CodingStyle: {} should be used in all branches if used in at least one.
>
> MBR, Sergei
>

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

* Re: [PATCH 2/2] libata-scsi: better style in ata_msense_caching()
  2016-07-07 12:44     ` Tom Yan
@ 2016-07-07 13:00       ` Sergei Shtylyov
  0 siblings, 0 replies; 4+ messages in thread
From: Sergei Shtylyov @ 2016-07-07 13:00 UTC (permalink / raw)
  To: Tom Yan; +Cc: Tejun Heo, linux-ide, linux-scsi

On 07/07/2016 03:44 PM, Tom Yan wrote:

> Sorry I am a bit new in this. Does that mean I should also use {} for
> the if clause even it has only one line of statement, because I
> (needed to) use that for the else clause? So it should be like:

>
> if ... {
>     ...
> } else {
>     ...
>     ...
> }

    Exactly, see Documentation/CodingStyle, chapter 3.

MBR, Sergei


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

end of thread, other threads:[~2016-07-07 13:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20160707014334.1031-1-me>
2016-07-07  1:43 ` [PATCH 2/2] libata-scsi: better style in ata_msense_caching() tom.ty89
2016-07-07 10:55   ` Sergei Shtylyov
2016-07-07 12:44     ` Tom Yan
2016-07-07 13:00       ` Sergei Shtylyov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox