Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp2596056ybg; Fri, 31 Jul 2020 05:00:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPXMYRkZFrCMMwhZj0RtLs90ijWCBf5m3sedWwAQhtDSpqsq3dRJBeVAv4Jy+XoRywz7UC X-Received: by 2002:a50:a6d2:: with SMTP id f18mr3454937edc.374.1596196800601; Fri, 31 Jul 2020 05:00:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596196800; cv=none; d=google.com; s=arc-20160816; b=uTvYYj8cLSo+EqyU3/lcHuX5DJoDflL3+xjPe5lDdXP6oMs7sHjNMq3hdT7g31Doys Y54vwdazcNP5cwWaIwE9CObK85xjRw2yFKjHjB0x/zCkFKD6U6Y99ynkKMcSdkmuRXz0 VyAnbs5V3wpxGVwbL2rwNxbIRkNqOVgiMsYw9HH0BoZzQUVyW4nO6/G/HE0NjQF2mIGJ JH3NtmgSudWTjW0cpDiNTEctEo56CC8/yL8AmmS7Ih2YR0mCqh9jknbVyw2C9yNkaaKF me2+J7VUA71eZsA1pqjxMZxhRDWm5b0h1X27YnMAJAHvj9qEOPu2Kq6JPi9ISD7Lhm6w vMqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=zYU7VCJXWthlUgkj7Fe1H543i6bzHa15+x9CJAoaAUU=; b=nGpUIylGZvilxeZVCdVE/jnJ8I1vrUI5WbihSFro3NO7h8Vh2VZtawVqYognd85Sl4 uv1rU/rIRKsrlcngujlYLA4Wg21nq71RfgYybEXNCow6RtvnELqc2b62lKDjGCz7MUVF g985SDPeaQG35ZfLWg6ooV4T9hUssFVlgKyYSGhJ3G30+p/GQAHo+iCJ83UCsERVm86Q y6vJujCewBx8kXkejGJq6dNzELEEak8URFOwhzOWEzETyCxe3ImvQ6NOBlJflTvRoib9 0yZVqv/86yHMpxAqmJoE7+H7zT+qUp4nzHxantAuu2s7mGkBUyE0FH6PPJvmHsPUjqMp OMQg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y16si5116107edu.65.2020.07.31.04.59.38; Fri, 31 Jul 2020 05:00:00 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732882AbgGaL7Q (ORCPT + 99 others); Fri, 31 Jul 2020 07:59:16 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:51810 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732689AbgGaL7P (ORCPT ); Fri, 31 Jul 2020 07:59:15 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 400E1FFCCF478D1BCD9E; Fri, 31 Jul 2020 19:59:09 +0800 (CST) Received: from [127.0.0.1] (10.174.179.63) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Fri, 31 Jul 2020 19:58:59 +0800 Subject: Re: [PATCH -next] tools build: Check return value of fwrite_unlocked in jvmti_agent.c To: Arnaldo Carvalho de Melo , Ian Rogers CC: , Li Bin , Jiri Olsa , LKML , linux-perf-users References: <20200724100706.48330-1-bobo.shaobowang@huawei.com> <20200730100357.GD424218@kernel.org> From: "Wangshaobo (bobo)" Message-ID: Date: Fri, 31 Jul 2020 19:58:58 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.1.0 MIME-Version: 1.0 In-Reply-To: <20200730100357.GD424218@kernel.org> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.63] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2020/7/30 18:03, Arnaldo Carvalho de Melo 写道: > 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 > I am sorry I forgot what does fwrite_unlocked return, as same as fwrite error happens, the return val is a short item count (or zero)  but not equals the items written. I have fixed it and already sent v2 and address Ian review, thanks a lot. ... and i refer to the writing of function jvmti_write_debug_info() for giving out exit label, thanks again, - Wang ShaoBo >> 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 >>>