Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2151712pxa; Mon, 3 Aug 2020 08:43:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLn4od2JMbsNFdfbPdi0l9GJ3Hb8b0UBbcEX8CieJQp/AxM72s/qIqNq5+eKvUV3DNHyC0 X-Received: by 2002:a05:6402:1a26:: with SMTP id be6mr16072720edb.162.1596469384492; Mon, 03 Aug 2020 08:43:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596469384; cv=none; d=google.com; s=arc-20160816; b=NiBX3jQ5XuluDzVUGxQCYBqn95mgC7wwV2ryEUeB4FqECnHgZjtQo7z7Q65hHnWsQB wxc0EXninr5gt0QU4xxoKAhe8hLxPukJp+8QDDd6ZakyUNtKxZz8S0Tfi0PXPp2BSJe8 GA4c6FjrNKrmrD0mHMuRiN4eOzy0LBEeir7Ir2k0T80dK8/4+Hc5qpGHCVLztS9voh7/ gcvGEsg4O5ZTmOelO3uR82nQ/hzLtOHwQvVjeu2++FkMs55Miv2DBVnDfOOcOpHB8sNt d1AvBUkvWhdNoiLG1j1iv7AekHFkpUofg6/br82FdILKiIMuw/tr4rV1e0IPiZ6e0gsc WzHw== 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=XLXMroI9RZKFZ/jbE2T9kC6SWd2fACmZd1CP7cneKVM=; b=mV5hi9kMDt3qnHFwe9qJivB4KPMzdFtywG5eqjJRKFcB3FTvmv1ZXSBpT9DW+W2bsV IMzEHXThb0u6tDgcxUHC+s61ikMNQVNxZoWh6KkVZ9+iyqZoZDQsKaUVeUIMaWmY2Bvg pggpsSRvYM0H3oV+YuJPiXwCflQikDhl7eM9u4giG0Mtne+5tsON83vi6/WQSbnIqqPU Ae2qXOuIKWtSgaVMrJUpELs0+mAM2AqCzNmEXiiO6jxYWDb1UrrsGdk8qyf17yULhiC4 xIn19SaOYupVzdXRs/6YyzbMVLWXlLVzBjQwikyySEVRMeO6VqLlM8i3ovn6JMwvUhxp P/qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=OdVncMUe; 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 d6si10238640ejp.151.2020.08.03.08.42.42; Mon, 03 Aug 2020 08:43:04 -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=OdVncMUe; 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 S1727887AbgHCPmL (ORCPT + 99 others); Mon, 3 Aug 2020 11:42:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727070AbgHCPmL (ORCPT ); Mon, 3 Aug 2020 11:42:11 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10A04C061756 for ; Mon, 3 Aug 2020 08:42:11 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id r2so29573573wrs.8 for ; Mon, 03 Aug 2020 08:42:10 -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=XLXMroI9RZKFZ/jbE2T9kC6SWd2fACmZd1CP7cneKVM=; b=OdVncMUe7vse9R2wbxQY1D5HUGHp3kUEjL9lIul4+4jUpyj7NUhPm3dIY25SZkfDWU TBnBtFJBB+04cazx6KTj4ZYiMgLbCB8J/xWZUH6FE/5tqZIB/T6QJo74kzHdOPLfn3ws RTnn1wWKM9Bmhb8a2tPmpSh77XV4XFJ//4ABySZ/UkE8AcWDE35YemtaeZfLjM8amaut xU7qB7ygXSeoEeYcckTt8OcRb34gg6zDo5f6AJcPz6bdp1mX0+t9zRFboEnP+nK2fbzE HHhajtdxcJFAkW+JBB4RG8yfCWsUUbtOVbUXah8oZyaxeONuzthTPfyZkF0yp9FtvtA5 H0FQ== 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=XLXMroI9RZKFZ/jbE2T9kC6SWd2fACmZd1CP7cneKVM=; b=XplvXpLTZb4/3/o/1RrvwoeAajN2zs/nF/d3Xy3UVVOtuMPOFVzSqiFhyJlryNPAEo xRsMUuHV3VsqRn4pBgUVfVmtMEASdlPAfgrMSwpCTFQDHNQoCZtQZ/S5R5qxF7EKvRcL 2zAuR+dmroKFmfwfGTfOkKAJFhFk1d5MVZzW7BhuWKepdWi4Xt1pFAbSWMS/hWD1V9Z0 RWT951Ppcq5tDbxjwu5sKw0NpawdpSAkSCn9+OczCKiP7yx8Q2640poUbabmyQWG82BH luGeYWQZ78HNZqD5fh3Sfi8K4xid6qZ0KuhZ3KFOgy7LdoMW2ivpP46jaxEMNTGLiFry O6eA== X-Gm-Message-State: AOAM533DspmYg7mx/d9cEAiJV2x7yDNrXKuOQlLZy7tSAMNX1OAXRKQS O4pOGJsQHUmDbMbm5VxwaMfww9Wv7LUszGVCMO8qCQ== X-Received: by 2002:adf:fe0c:: with SMTP id n12mr15023161wrr.48.1596469329582; Mon, 03 Aug 2020 08:42:09 -0700 (PDT) MIME-Version: 1.0 References: <20200731114214.25654-1-bobo.shaobowang@huawei.com> In-Reply-To: <20200731114214.25654-1-bobo.shaobowang@huawei.com> From: Ian Rogers Date: Mon, 3 Aug 2020 08:41:58 -0700 Message-ID: Subject: Re: [PATCH v2 -next] tools build: Check return value of fwrite_unlocked in jvmti_agent.c To: Wang ShaoBo Cc: cj.chengjian@huawei.com, Arnaldo Carvalho de Melo , Li Bin , 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 31, 2020 at 4:42 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 Thanks, looks good now! Reviewed-by: Ian Rogers > --- > tools/perf/jvmti/jvmti_agent.c | 25 ++++++++++++++++--------- > 1 file changed, 16 insertions(+), 9 deletions(-) > > diff --git a/tools/perf/jvmti/jvmti_agent.c b/tools/perf/jvmti/jvmti_agent.c > index 88108598d6e9..dfb6cb8564cb 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 sret; > > /* don't care about 0 length function, no samples */ > if (size == 0) > @@ -400,17 +400,24 @@ 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); > + sret = fwrite_unlocked(&rec, sizeof(rec), 1, fp); > + if (sret != 1) > + goto error; > + sret = fwrite_unlocked(sym, sym_len, 1, fp); > + if (sret != 1) > + goto error; > > - if (code) > - fwrite_unlocked(code, size, 1, fp); > + if (code) { > + sret = fwrite_unlocked(code, size, 1, fp); > + if (sret != 1) > + goto error; > + } > > funlockfile(fp); > - > - ret = 0; > - > - return ret; > + return 0; > +error: > + funlockfile(fp); > + return -1; > } > > int > -- > 2.25.1 >