diff mbox

[2/2] libata-scsi: better style in ata_msense_caching()

Message ID 577db3cf.0a6a620a.c3774.1508@mx.google.com
State Not Applicable
Delegated to: David Miller
Headers show

Commit Message

Tom Yan July 7, 2016, 1:43 a.m. UTC
From: Tom Yan <tom.ty89@gmail.com>

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

Comments

Sergei Shtylyov July 7, 2016, 10:55 a.m. UTC | #1
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

--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Tom Yan July 7, 2016, 12:44 p.m. UTC | #2
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
>
--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sergei Shtylyov July 7, 2016, 1 p.m. UTC | #3
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

--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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);
 }