Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1803272ybg; Thu, 30 Jul 2020 03:07:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlnEWGsEakUEdZkHgn3uOhFeG9radSpBkUCd1vaXogQbGXF/O7Ms7UrP7Rl+4xbeME0NRD X-Received: by 2002:a50:d697:: with SMTP id r23mr1853463edi.223.1596103650534; Thu, 30 Jul 2020 03:07:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596103650; cv=none; d=google.com; s=arc-20160816; b=fvSNcbxFCIEOseLm3VYfoATK4mk35OzsO9wstYqi3uxVjKvLlPrUpD8V3ww5mPZGaa qvGnp6OqIlat31jr90cdiSND0ISs2jHf4EFlVYcwvsX7hXtHHmhrquB2ZhCVEviujiXa OPnVgcScY457X9jZp5FHpzV+hs7LBIyb6s/EdbNBPXeAN1ltd0SSQAMC6XlaAuQMwrYZ V1AFl9FdTfEC8rtEKPaGiFROjsIMWywMdwq+Vf7slTXcXdCy2rANVuXDK1xi506IZw+f zcjiDZlO6ToV3V09COIHdCrv+33KFkedJCGNVQRLgMvGSHZUEI+95Qo2vFFzfsBf+PtY AJCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=dEjcWhRO0BOEr6WeN1mqyFeypmswMToJL3wfv7Shq2M=; b=KEI/NV7BE8Z7RxzLZYjkIkA2gW2ZGTjyTVbIcT/vhfz9/3CJIoQANrdJfLtBMNWza3 NVxSe3VwNiLFu8JIIJf8DDmiJ5qhjlvfGMpCyJx3tkhQbgq2KrNnSrYrskRjFmzvCEH4 JRgIDhaKQkMOOuxIBd9SGZUu69RfFyeRaTMWiFQqXAhwW128g7cVc8mR+ulwBZTrK2z7 uXku0rPkQ8HrP71mv215AWxOszuTfx3E1Em5h56NzzycPnv5o1lMZnC0gOfppUxWyyZ7 F77Wkfgv7he2XkEf8murPL8FVNxWGDuteRAXpajis+W6TgKu6MWOV7IvnnvLprcRXCeA Ahxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uUU9CgLC; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id df1si3056250edb.78.2020.07.30.03.07.08; Thu, 30 Jul 2020 03:07:30 -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=@kernel.org header.s=default header.b=uUU9CgLC; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727015AbgG3KEA (ORCPT + 99 others); Thu, 30 Jul 2020 06:04:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:56804 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726799AbgG3KEA (ORCPT ); Thu, 30 Jul 2020 06:04:00 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.37.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 59DCB206F5; Thu, 30 Jul 2020 10:03:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596103439; bh=eljX3hl3K/RgvgEJymDxfIjALfZUJgDGHliBMGzUt+4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=uUU9CgLCIvvZrtQtrr5LIYw3qBeezpEusGOnlllQEsJ+BV+N4PFvJr5knWU7czg1s aEPm6vxXQ5zm8pDvxg98tpXR3uZppmNX7KMfMl8sDZVA3qwgjVLnh7AMi6gS07Po7h tMUzIZ1Az54cJTa4hch/sOQsI0nrYOSUZgJ7dAk8= Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 8A40B40E57; Thu, 30 Jul 2020 07:03:57 -0300 (-03) Date: Thu, 30 Jul 2020 07:03:57 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers Cc: Wang ShaoBo , cj.chengjian@huawei.com, Li Bin , Jiri Olsa , LKML , linux-perf-users Subject: Re: [PATCH -next] tools build: Check return value of fwrite_unlocked in jvmti_agent.c Message-ID: <20200730100357.GD424218@kernel.org> References: <20200724100706.48330-1-bobo.shaobowang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Wed, Jul 29, 2020 at 04:47:36PM -0700, Ian Rogers escreveu: > 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? Yeah, I removed it from tmp.perf/core. Wang, please address Ian review, and consider having just one out exit label. - Arnaldo > 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 > > -- - Arnaldo