Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1558183ybg; Wed, 29 Jul 2020 18:13:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoXf7bk+7dpYYak6gmuNLmcqdT7HeS/1UTgK+bUV3iYAu4t+LN1AYoJAs4Cid9zNXLHEg3 X-Received: by 2002:a50:da05:: with SMTP id z5mr413099edj.207.1596071623847; Wed, 29 Jul 2020 18:13:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596071623; cv=none; d=google.com; s=arc-20160816; b=tJlkNTTQ0H976BYtS+KSpnBP4imJMDw/I9GxssmPkhF39/CzTBvZdrXBB7piFbsozG DZkj4/nCJtJCdgv2Dq12Xs59ohiQl2NHNlzVV7JLP1Q0lHUmUYHhE74ufH+GiL3HH6+q d47H1MKp3JaAO2fjskkAqMvcYoBnM5H8W8kpOy2WwsPbYWa7Fo1SuTDuXucVWNdxLtut cPQ5c//RczpXj+w3G3eweOKqwg9lY7UhLzAfD4/5hSOlTB3fnqHMo+/zm1JzgVfHU2hd wvr3pVKbIBoXL/pDrKzLZUXO3vPvRKZ5JKlJllk/vMFFlv5hZ7N0/gHrX5b3aFV6hpyH Aa2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:from:cc:to:subject :content-transfer-encoding:mime-version:references:in-reply-to :user-agent:date:dkim-signature; bh=29jI3ci+a7Sp9d2xnBWnJDwqEUNpCdqc7ZH0hJFRuMU=; b=kNSZVG0h9XvPy65ndoP2ZV8O/2A8SHX3afrM5aBBxzwUjycngZud+Fh4Kme9T3S2uE s/dxp7Ld+T4QYPwGtwBsToyT4LjUIq2MaMIiVS4nYvLlmVPztTFxF8luXRellL551qBp SWZv1fABGrgdhLI+4X5F2JvfiYvtNCjq/Qgruqqt5BtP3ZDiab9d31OfXaZ5k2b0i0Zq EpWXo0xn5CTHBw+gD8ry03EOlLyK4Tcxp6PRJmwJF4xnEqDpeJdQ0VfpyPFyjuJC6p9W Mv+ZK0Tg/A41fhPrVoyPaGedED+We/VWTuCebJ+DxBbMntOy6LGdgu/OX+GIj71iHAMm BhZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=YBnTtUAF; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fy16si2191786ejb.15.2020.07.29.18.13.21; Wed, 29 Jul 2020 18:13:43 -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=fail header.i=@gmail.com header.s=20161025 header.b=YBnTtUAF; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726781AbgG3BNM (ORCPT + 99 others); Wed, 29 Jul 2020 21:13:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726194AbgG3BNL (ORCPT ); Wed, 29 Jul 2020 21:13:11 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BD7CC061794; Wed, 29 Jul 2020 18:13:11 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id e13so24200763qkg.5; Wed, 29 Jul 2020 18:13:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:user-agent:in-reply-to:references:mime-version :content-transfer-encoding:subject:to:cc:from:message-id; bh=29jI3ci+a7Sp9d2xnBWnJDwqEUNpCdqc7ZH0hJFRuMU=; b=YBnTtUAF9rZY2tbC6ODuETMDGQDuNtrq+FlAGUKdQm9jZnv0UGMruYUV0RRme+vrrV bwvAHFXDbCcDaxEjLzfFXQA6KqomF8scOa+ss8EBzhTHr/0wBQ5T1rIGc89PaIHjBJ1M rjfaQ9ZDDEwWkzybyscEgShEMeToKnAQsfHuC8n71Yywr/dVewTU9YYtjIpeN8Xktf16 T8qnIoLsUx7APgfCXee96lq8PAyFamdS/JUgsSOnPve9/a7RhGccbdi4KxDCIYRRrake U21XWbNO32efXdZcDVUxvgdHE2432M4SXLbQRxwn9CrDXnZj8cPmF6uFaJ97uJAVOI67 f3lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:user-agent:in-reply-to:references :mime-version:content-transfer-encoding:subject:to:cc:from :message-id; bh=29jI3ci+a7Sp9d2xnBWnJDwqEUNpCdqc7ZH0hJFRuMU=; b=g2WwfBgvhbWoI4MsL8CvmFjdQpUuiSlWSEADdo68OIdjBMDMxUJHX1IUT1daZfm0xY 2wtBuUDVP1a3GsmhcwY6eyeVk+CnDCgfvR2v+VHgDAdylZI732vB/vQWfQVOe+t+Rqy3 GOgdfYEMfT1h0zJKn9pXvKYba653JliHTj/UWJrgU+mfNSG4PorBVB47pO9BUVSD5I9T INw6KtCY8nPGBrtuoKcanOh0DtIAOTLuXIlvtgLH4iN5s4APASxKQBCCjBlzQevQ5Tcw U6btO/6TYk03fU/dPYRudNsp5eFlaEdE4Xo4xmYt3sUPKgo5SrXcVPIkiKrKY98xTPPj Kisw== X-Gm-Message-State: AOAM530WzeOeN+D5dhmyNqvoar51lLaG69i2rrub+fKrRejGnhDRRQah 2kC2PbvYedV5UT91ITl9qSU= X-Received: by 2002:a37:4048:: with SMTP id n69mr34076346qka.421.1596071590282; Wed, 29 Jul 2020 18:13:10 -0700 (PDT) Received: from RedmiNote8Pro-Redmi.localdomain ([179.97.37.151]) by smtp.gmail.com with ESMTPSA id k31sm1838251qtd.60.2020.07.29.18.13.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jul 2020 18:13:09 -0700 (PDT) Date: Wed, 29 Jul 2020 22:12:46 -0300 User-Agent: K-9 Mail for Android In-Reply-To: References: <20200724100706.48330-1-bobo.shaobowang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH -next] tools build: Check return value of fwrite_unlocked in jvmti_agent.c To: Ian Rogers , Wang ShaoBo CC: cj.chengjian@huawei.com, Li Bin , Jiri Olsa , Arnaldo Carvalho de Melo , LKML , linux-perf-users From: Arnaldo Carvalho de Melo Message-ID: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On July 29, 2020 8:47:36 PM GMT-03:00, Ian Rogers w= rote: >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=2E >> >> Signed-off-by: Wang ShaoBo >> --- >> tools/perf/jvmti/jvmti_agent=2Ec | 23 +++++++++++++++-------- >> 1 file changed, 15 insertions(+), 8 deletions(-) >> >> diff --git a/tools/perf/jvmti/jvmti_agent=2Ec >b/tools/perf/jvmti/jvmti_agent=2Ec >> index 88108598d6e9=2E=2Ea1fe6aa16b6d 100644 >> --- a/tools/perf/jvmti/jvmti_agent=2Ec >> +++ b/tools/perf/jvmti/jvmti_agent=2Ec >> @@ -363,7 +363,7 @@ jvmti_write_code(void *agent, char const *sym, >> struct jr_code_load rec; >> size_t sym_len; >> FILE *fp =3D agent; >> - int ret =3D -1; >> + int ret; >> >> /* don't care about 0 length function, no samples */ >> if (size =3D=3D 0) >> @@ -401,16 +401,23 @@ jvmti_write_code(void *agent, char const *sym, >> rec=2Ecode_index =3D code_generation++; >> >> ret =3D 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=2E Won't ret here be the number >of items written and not an error code? Consequently all writes will >immediately goto error? Good thing this is in tmp=2Eperf/core, you're right, the test has to be (r= et < 0)=2E=2E=2E I'll fix, thanks! Also we need some 'perf test' for this :-/ - Arnaldo > >Thanks, >Ian > >> + ret =3D fwrite_unlocked(sym, sym_len, 1, fp); >> + if (ret) >> + goto error; >> >> - if (code) >> - fwrite_unlocked(code, size, 1, fp); >> + if (code) { >> + ret =3D fwrite_unlocked(code, size, 1, fp); >> + if (ret) >> + goto error; >> + } >> >> funlockfile(fp); >> - >> - ret =3D 0; >> - >> - return ret; >> + return 0; >> +error: >> + funlockfile(fp); >> + return -1; >> } >> >> int >> -- >> 2=2E17=2E1 >> --=20 Sent from my Android device with K-9 Mail=2E Please excuse my brevity=2E