[Qemu-devel] [PATCH v3 20/25] s390x/sclp: Use a const variable to improve readability

Philippe Mathieu-Daudé posted 25 patches 6 years, 8 months ago
Maintainers: Anthony Perard <anthony.perard@citrix.com>, Li Zhijian <lizhijian@cn.fujitsu.com>, Jason Wang <jasowang@redhat.com>, Cornelia Huck <cohuck@redhat.com>, Amit Shah <amit@kernel.org>, "Michael S. Tsirkin" <mst@redhat.com>, Paul Durrant <paul.durrant@citrix.com>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@de.ibm.com>, David Gibson <david@gibson.dropbear.id.au>, Zhang Chen <zhangckid@gmail.com>, Corey Minyard <minyard@acm.org>, Gerd Hoffmann <kraxel@redhat.com>, Stefano Stabellini <sstabellini@kernel.org>, Paolo Bonzini <pbonzini@redhat.com>, Stefan Berger <stefanb@linux.ibm.com>, Samuel Thibault <samuel.thibault@ens-lyon.org>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
[Qemu-devel] [PATCH v3 20/25] s390x/sclp: Use a const variable to improve readability
Posted by Philippe Mathieu-Daudé 6 years, 8 months ago
We will reuse this variable in the next patch.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/char/sclpconsole-lm.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/hw/char/sclpconsole-lm.c b/hw/char/sclpconsole-lm.c
index dbc91a1e5b..49543e2c83 100644
--- a/hw/char/sclpconsole-lm.c
+++ b/hw/char/sclpconsole-lm.c
@@ -210,13 +210,14 @@ static int process_mdb(SCLPEvent *event, MDBO *mdbo)
     int rc;
     int len;
     uint8_t buffer[SIZE_BUFFER];
-
-    len = be16_to_cpu(mdbo->length);
-    len -= sizeof(mdbo->length) + sizeof(mdbo->type)
+    const size_t hlen = sizeof(mdbo->length)
+            + sizeof(mdbo->type)
             + sizeof(mdbo->mto.line_type_flags)
             + sizeof(mdbo->mto.alarm_control)
             + sizeof(mdbo->mto._reserved);
 
+    len = be16_to_cpu(mdbo->length);
+    len -= hlen;
     assert(len <= SIZE_BUFFER);
 
     /* convert EBCDIC SCLP contents to ASCII console message */
-- 
2.20.1


Re: [Qemu-devel] [PATCH v3 20/25] s390x/sclp: Use a const variable to improve readability
Posted by Cornelia Huck 6 years, 8 months ago
On Wed, 20 Feb 2019 02:02:27 +0100
Philippe Mathieu-Daudé <philmd@redhat.com> wrote:

> We will reuse this variable in the next patch.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  hw/char/sclpconsole-lm.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/char/sclpconsole-lm.c b/hw/char/sclpconsole-lm.c
> index dbc91a1e5b..49543e2c83 100644
> --- a/hw/char/sclpconsole-lm.c
> +++ b/hw/char/sclpconsole-lm.c
> @@ -210,13 +210,14 @@ static int process_mdb(SCLPEvent *event, MDBO *mdbo)
>      int rc;
>      int len;
>      uint8_t buffer[SIZE_BUFFER];
> -
> -    len = be16_to_cpu(mdbo->length);
> -    len -= sizeof(mdbo->length) + sizeof(mdbo->type)
> +    const size_t hlen = sizeof(mdbo->length)
> +            + sizeof(mdbo->type)
>              + sizeof(mdbo->mto.line_type_flags)
>              + sizeof(mdbo->mto.alarm_control)
>              + sizeof(mdbo->mto._reserved);
>  
> +    len = be16_to_cpu(mdbo->length);
> +    len -= hlen;
>      assert(len <= SIZE_BUFFER);
>  
>      /* convert EBCDIC SCLP contents to ASCII console message */

I'd probably merge this with the next patch, though.

Reviewed-by: Cornelia Huck <cohuck@redhat.com>

Re: [Qemu-devel] [PATCH v3 20/25] s390x/sclp: Use a const variable to improve readability
Posted by Philippe Mathieu-Daudé 6 years, 8 months ago
On 2/20/19 11:53 AM, Cornelia Huck wrote:
> On Wed, 20 Feb 2019 02:02:27 +0100
> Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
> 
>> We will reuse this variable in the next patch.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> ---
>>  hw/char/sclpconsole-lm.c | 7 ++++---
>>  1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/hw/char/sclpconsole-lm.c b/hw/char/sclpconsole-lm.c
>> index dbc91a1e5b..49543e2c83 100644
>> --- a/hw/char/sclpconsole-lm.c
>> +++ b/hw/char/sclpconsole-lm.c
>> @@ -210,13 +210,14 @@ static int process_mdb(SCLPEvent *event, MDBO *mdbo)
>>      int rc;
>>      int len;
>>      uint8_t buffer[SIZE_BUFFER];
>> -
>> -    len = be16_to_cpu(mdbo->length);
>> -    len -= sizeof(mdbo->length) + sizeof(mdbo->type)
>> +    const size_t hlen = sizeof(mdbo->length)
>> +            + sizeof(mdbo->type)
>>              + sizeof(mdbo->mto.line_type_flags)
>>              + sizeof(mdbo->mto.alarm_control)
>>              + sizeof(mdbo->mto._reserved);
>>  
>> +    len = be16_to_cpu(mdbo->length);
>> +    len -= hlen;
>>      assert(len <= SIZE_BUFFER);
>>  
>>      /* convert EBCDIC SCLP contents to ASCII console message */
> 
> I'd probably merge this with the next patch, though.

The context is easier to review in 2 different patches IMHO.

> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
> 

Thanks!

Phil.