Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1517343ybg; Wed, 29 Jul 2020 16:50:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGbQXYzySiAIhsHQHc3GEkRUWwtcvIjTPL/JqXug0ipFOfSftDcTEEdQ5eP2MjdgGEWrCm X-Received: by 2002:a17:906:a41:: with SMTP id x1mr43591ejf.209.1596066628549; Wed, 29 Jul 2020 16:50:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596066628; cv=none; d=google.com; s=arc-20160816; b=z32Zp0da1RpzYkCdFZm3t7L4WI8bCVW2WI9TPatzZ7insrcJUYOPg7OtuHpW6KUvW8 oLxc5TbtJ20bImostGKxo/c4RY9D57ocLCQZxvGG+QOBnekcHOVBspYMR7+Y9MgsAF3Q MyuZ3a6uowgUgFOjIxpWC1vjfLwDFdVb15WRkm6hQF5GHUr3aNXDcVzvJ6b9lAKkS5CN MjGlMJbQIp2eiuhslr2gd103kvE56jEkp+mISHHemJbUze8oTJuMbNAZej0gv6GhpMiO DUZ89ATBaN34GahXV4cCswSlU6SQM1/tsmmCX79DE5n6NtY/+rRtRmJOcgnyoUVlbfKZ 7g1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=8Yb8JOoh+LSsOfdrY/X9ZAwRyZ4kLPnC6nnWUaDd9tc=; b=i3d8rtxMlm1NW339wFgIGk2riTVUR2SxNzwtK3t9tx26JfHznFRqbZ2xr9o3rWSSa5 Ebsrj0t/NQJRFelYO8LCsu+c6xj0pc/ZmsanQTARPnFNyCRiydO1I1D9e3jeAGmheXh+ YKJjf2OjBpRVaZgV2ZIRm1ce/blntQpGxmm9sDZZYHJZzC9oijTtdw6k3ITDZFeezZRy jfw/ZJxXwXD2Kd5eMNw+nWrv5/sck/DHu0EqUCMtMGI1r8rEet6s/wnRcLdGIt3W46gQ jmASW/+bzwZIArzEC4XZhSp79XIx9trp8D8k1fnAoAAxDXHx8BlkiGqGc00965H4R8KS feZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=DIdFres5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r26si1941452ejz.728.2020.07.29.16.50.05; Wed, 29 Jul 2020 16:50:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=DIdFres5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728112AbgG2Xru (ORCPT + 99 others); Wed, 29 Jul 2020 19:47:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728010AbgG2Xrt (ORCPT ); Wed, 29 Jul 2020 19:47:49 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1244FC0619D2 for ; Wed, 29 Jul 2020 16:47:49 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id f1so22626782wro.2 for ; Wed, 29 Jul 2020 16:47:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8Yb8JOoh+LSsOfdrY/X9ZAwRyZ4kLPnC6nnWUaDd9tc=; b=DIdFres5Tl0wvrFB+fV7XnLJIh0s3Mx7Nf0HnayGSLVRNXGZ7hGXtBGliczuymiZ1z Iw3nDLtxttfnafX/ne+/ag+iZfQVnWEayVP6KNkMEn2DSmInHFdDr5dihgquTWd22rfp wg5yuDm5f6fXU6cCAW097RA7NxPfimeOKMImel28VeoArOsaHebtEo5+7kPgB+qJCttJ nfYJdF8AZCBMo4NL+F1Tm4EFeF67dSpW3ygCenqbgjqYcO3nglgoDX7FR9fB04aK26tT wkmb7g5mSF8m7Qs3zIzS8UHXGu+zjrtULZZTq7Qe4ww1dyZBsqJZqyaKk4LwogcBgjus sA/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8Yb8JOoh+LSsOfdrY/X9ZAwRyZ4kLPnC6nnWUaDd9tc=; b=J9Y2DfcCdfmEN92jgv+bjluiX3fXm+9/KlPnLMbSBHKzbuMF9D/qA+wrIfwuO3L47Q oFcF9aMHXNlGx+0Tn3XaOATxe1wpRx1fmGsCjLyzifBSw7lKqiiN2CLPr95oUOWdX6ac BGfwQbV0irVhKvnIWDK2neMEsOF+wUfSbyR6FstNDuhZkqGBwXkYalhQgf8dTcsREGkz ILgxa2277paLhYCqpXXD66XN39IQnTWcxwUkVUAvuVLxrpgbHATTJaGPLWxgJI0wEvKp aTQ9qjV1QEUnqgPQ1Rh1pbcbmrwJ1ph/te7DcJ5Jy2liFna7cHUoEMT9GPcmOSCEJAQ1 JQxg== X-Gm-Message-State: AOAM532WiayizT3Xz9NsA3mXaMROUjiFY/z1xRZRqKfTk4aaqg2ONl93 MAah8n8qePrSQn2LEVRFkH3Evwp90SF/Nh7sx81oiA== X-Received: by 2002:adf:fe0c:: with SMTP id n12mr89894wrr.48.1596066467544; Wed, 29 Jul 2020 16:47:47 -0700 (PDT) MIME-Version: 1.0 References: <20200724100706.48330-1-bobo.shaobowang@huawei.com> In-Reply-To: <20200724100706.48330-1-bobo.shaobowang@huawei.com> From: Ian Rogers Date: Wed, 29 Jul 2020 16:47:36 -0700 Message-ID: Subject: Re: [PATCH -next] tools build: Check return value of fwrite_unlocked in jvmti_agent.c To: Wang ShaoBo Cc: cj.chengjian@huawei.com, Li Bin , Jiri Olsa , Arnaldo Carvalho de Melo , LKML , linux-perf-users Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 24, 2020 at 3:07 AM Wang ShaoBo wrote: > > Function jvmti_write_code called by compiled_method_load_cb may return > error in using fwrite_unlocked, this failure should be captured and > warned. > > Signed-off-by: Wang ShaoBo > --- > tools/perf/jvmti/jvmti_agent.c | 23 +++++++++++++++-------- > 1 file changed, 15 insertions(+), 8 deletions(-) > > diff --git a/tools/perf/jvmti/jvmti_agent.c b/tools/perf/jvmti/jvmti_agent.c > index 88108598d6e9..a1fe6aa16b6d 100644 > --- a/tools/perf/jvmti/jvmti_agent.c > +++ b/tools/perf/jvmti/jvmti_agent.c > @@ -363,7 +363,7 @@ jvmti_write_code(void *agent, char const *sym, > struct jr_code_load rec; > size_t sym_len; > FILE *fp = agent; > - int ret = -1; > + int ret; > > /* don't care about 0 length function, no samples */ > if (size == 0) > @@ -401,16 +401,23 @@ jvmti_write_code(void *agent, char const *sym, > rec.code_index = code_generation++; > > ret = fwrite_unlocked(&rec, sizeof(rec), 1, fp); > - fwrite_unlocked(sym, sym_len, 1, fp); > + if (ret) > + goto error; Sorry, it seems I lost a reply to this. Won't ret here be the number of items written and not an error code? Consequently all writes will immediately goto error? Thanks, Ian > + ret = fwrite_unlocked(sym, sym_len, 1, fp); > + if (ret) > + goto error; > > - if (code) > - fwrite_unlocked(code, size, 1, fp); > + if (code) { > + ret = fwrite_unlocked(code, size, 1, fp); > + if (ret) > + goto error; > + } > > funlockfile(fp); > - > - ret = 0; > - > - return ret; > + return 0; > +error: > + funlockfile(fp); > + return -1; > } > > int > -- > 2.17.1 >