diff mbox

target-ppc: fix warn_unused_result build break with in-kernel HTAB support

Message ID 20140212154030.393.66279.stgit@bahia.local
State New
Headers show

Commit Message

Greg Kurz Feb. 12, 2014, 3:40 p.m. UTC
The 7029677e4 commit introduced the following build break:

target-ppc/kvm.c: In function ‘kvmppc_hash64_write_pte’:
target-ppc/kvm.c:2017:10: error: ignoring return value of ‘write’, declared
with attribute warn_unused_result [-Werror=unused-result]
     write(htab_fd, &hpte_buf, sizeof(hpte_buf));
          ^

Even though nothing is done for the moment if kvm_htab_write() fails, we
obviously need to be explicit. Let's add an *empty* return path to please
gcc.

Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
---
 target-ppc/kvm.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Aneesh Kumar K.V Feb. 13, 2014, 3 a.m. UTC | #1
Greg Kurz <gkurz@linux.vnet.ibm.com> writes:

> The 7029677e4 commit introduced the following build break:
>
> target-ppc/kvm.c: In function ‘kvmppc_hash64_write_pte’:
> target-ppc/kvm.c:2017:10: error: ignoring return value of ‘write’, declared
> with attribute warn_unused_result [-Werror=unused-result]
>      write(htab_fd, &hpte_buf, sizeof(hpte_buf));
>           ^
>
> Even though nothing is done for the moment if kvm_htab_write() fails, we
> obviously need to be explicit. Let's add an *empty* return path to please
> gcc.
>

Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>

> Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> ---
>  target-ppc/kvm.c |   10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
> index 2eaf956..343376c 100644
> --- a/target-ppc/kvm.c
> +++ b/target-ppc/kvm.c
> @@ -2012,9 +2012,15 @@ void kvmppc_hash64_write_pte(CPUPPCState *env, target_ulong pte_index,
>      hpte_buf.hpte[0] = pte0;
>      hpte_buf.hpte[1] = pte1;
>      /*
> -     * Write the hpte entry
> +     * Write the hpte entry.
> +     * CAUTION: write() has the warn_unused_result attribute. Hence we
> +     * need to check the return value, even though we do nothing.
>       */
> -    write(htab_fd, &hpte_buf, sizeof(hpte_buf));
> +    if (write(htab_fd, &hpte_buf, sizeof(hpte_buf)) < 0) {
> +        goto out_close;
> +    }
> +
> +out_close:
>      close(htab_fd);
>      return;
>
Alexander Graf Feb. 13, 2014, 2:51 p.m. UTC | #2
On 13.02.2014, at 04:00, Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> wrote:

> Greg Kurz <gkurz@linux.vnet.ibm.com> writes:
> 
>> The 7029677e4 commit introduced the following build break:
>> 
>> target-ppc/kvm.c: In function ‘kvmppc_hash64_write_pte’:
>> target-ppc/kvm.c:2017:10: error: ignoring return value of ‘write’, declared
>> with attribute warn_unused_result [-Werror=unused-result]
>>     write(htab_fd, &hpte_buf, sizeof(hpte_buf));
>>          ^
>> 
>> Even though nothing is done for the moment if kvm_htab_write() fails, we
>> obviously need to be explicit. Let's add an *empty* return path to please
>> gcc.
>> 
> 
> Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>

Thanks, applied to ppc-next.


Alex
diff mbox

Patch

diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 2eaf956..343376c 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -2012,9 +2012,15 @@  void kvmppc_hash64_write_pte(CPUPPCState *env, target_ulong pte_index,
     hpte_buf.hpte[0] = pte0;
     hpte_buf.hpte[1] = pte1;
     /*
-     * Write the hpte entry
+     * Write the hpte entry.
+     * CAUTION: write() has the warn_unused_result attribute. Hence we
+     * need to check the return value, even though we do nothing.
      */
-    write(htab_fd, &hpte_buf, sizeof(hpte_buf));
+    if (write(htab_fd, &hpte_buf, sizeof(hpte_buf)) < 0) {
+        goto out_close;
+    }
+
+out_close:
     close(htab_fd);
     return;