Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1979250rdb; Mon, 9 Oct 2023 08:46:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkWGyefc9JCdF/1DF6+SviBv1q1gQSn+ZmnHhS/3pqu/CpMH5JupPYKALvPUZBqa8LdXcI X-Received: by 2002:a05:6a20:7d85:b0:137:c971:6a0c with SMTP id v5-20020a056a207d8500b00137c9716a0cmr17957756pzj.31.1696866369219; Mon, 09 Oct 2023 08:46:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696866369; cv=none; d=google.com; s=arc-20160816; b=zYB1TwJvWIeoKVgX2iKFYLlvP7BKiLi9MwJRQnUud9indgNti4DTD7UUjNBDwSiTCX DSPCox9IfLhHrh5o9wJh5BPOaw3vre9o/f99ocGSPbHcc/4LxR+QSsRrYSnRokKfuv0Y YD172UAwbWUIwCwc9d0/WMhej55Za3983XGxHo0zxYkgKS3K+2Vob5GRkcfWB2KMV00A azI38EipaIWvykVobNimSR9t+AtmzCJwm8o6gmKP5bhlvNr5NNilsT4+icsG6BvpRta9 GFj9/f5aLF0C9a5zcwUVJXoTYP+xMz+krfDpQEGr8T+gu+G3xgR+E28RK75VtaTIHAd1 j2vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=TfVtaRDig7D+Ty8+FieODZ141554VQ+ssPrPXjaViV4=; fh=3XBvd5tVoHgZQNsIrs8io5yGhaXHV9FXuQecuZ7UYG4=; b=Qx9HFMjKny8xu+2YPnMpODO0vQJbPk9W54IGBZpp7A32nk45Yo+uHJfGj6TWXmhGEm tXgAW+2WUgUyOAo9HqeZ7Ic5vAqHrkVl38Bi2t9cTCr1OzqQKkBpgAXqlh6Zv5KZh6rj 1EOvgwPrDlg3ig6XD8ZHOlo5XR4clDr/BU4atjRj3uOJzdhpYJezZOHOqCqj7ByJj/L4 kMP9CKPSXTxoZO6N+n4FHafkjMxXqvMbrH8m2s2Rle5x/eJJS8lWeW2QLyyc3XSMM5Jc IyLWdI0ZW2wdGWzorV04mYwGsftCpsiQuv8zqp7d/DiU95ZgRwI2r8OsmPPgLSDNtBiA cNrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1T9y0OuY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id cg20-20020a056a00291400b0068fcb779a3esi7334832pfb.278.2023.10.09.08.46.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:46:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1T9y0OuY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id A725180BC516; Mon, 9 Oct 2023 08:46:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376859AbjJIPpn (ORCPT + 99 others); Mon, 9 Oct 2023 11:45:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376901AbjJIPpl (ORCPT ); Mon, 9 Oct 2023 11:45:41 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1E15C5 for ; Mon, 9 Oct 2023 08:45:38 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-5068b69f4aeso7673e87.0 for ; Mon, 09 Oct 2023 08:45:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696866337; x=1697471137; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=TfVtaRDig7D+Ty8+FieODZ141554VQ+ssPrPXjaViV4=; b=1T9y0OuY4Di/oPxX0WRkVnisYCrqkSCYzZQq9xCp9RXvy8nqDtVzKAulHk6kp6Gy4L jYG3SH1aWScJg70xupLLk15aUiHX2iyKQk6I0qIR0kqlbPHRVaaLdEiVYd2gpXxd39MH UZ1cVpStnD8B78VPKr+IxYOgHbEJtdGm3EoJa81rt7wAcdtsmwypTl3iwKmHkmOWFJc5 CEc8eDEt00CKygbmJ/fx0qLgo0v48EquWrGZ+OuM0TTLLjMzAk+CkXpkNidUIteeTSR+ /R8OKSWgPvo5NPagTC10rzoMaYImlJb4ccp+cxKpinSBIZaj9jy0nRQFov2hG6hueQMF 2JSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696866337; x=1697471137; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TfVtaRDig7D+Ty8+FieODZ141554VQ+ssPrPXjaViV4=; b=J3AGl7cvwmwqv2MKMfLkTljAmwA6QD9Olh1IqEDY9XfOwvgIfLGmdYtXYV8it4oZgV 0jOCD7n0SiB95X3lii7nDsP6usRNW/SwbultYPD1OLfNKlkWS0fCM/xstaK5H7j5dcWn HS0tkxepOVEOpf0hoDEezMUMIN3gQdDgyomVW7/K+SNykNCXFZ0pVZVX+Vo2gz/HAp7d aceIf0DniX86L064e/s1qQeYhdK+P5vuujuVUx+mPTXpMfCzZpQwr/zt7DUzFPRr/m54 oRhhQbAJbDKO1dnaDg4Y4mYgzsSvZX/12P3P3vyhHE4CMwr5AnMDdstvGfuJHs40edMY CavQ== X-Gm-Message-State: AOJu0YwO/3E6ktCVjXTM+piYCO834Rnzpiyj2ebeIELpVVc3t2KqBRdz RwtiaWW3ZB50qwfLIHvKH2Ih877W2LdD0jQD0c81MQ== X-Received: by 2002:ac2:51a5:0:b0:501:a2b9:6046 with SMTP id f5-20020ac251a5000000b00501a2b96046mr220584lfk.7.1696866336692; Mon, 09 Oct 2023 08:45:36 -0700 (PDT) MIME-Version: 1.0 References: <20231005230851.3666908-1-irogers@google.com> <20231005230851.3666908-5-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Mon, 9 Oct 2023 08:45:25 -0700 Message-ID: Subject: Re: [PATCH v2 04/18] perf hisi-ptt: Fix potential memory leak To: Namhyung Kim Cc: Nathan Chancellor , Nick Desaulniers , Tom Rix , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Yicong Yang , Jonathan Cameron , Yang Jihong , Kan Liang , Ming Wang , Huacai Chen , Sean Christopherson , K Prateek Nayak , Yanteng Si , Yuan Can , Ravi Bangoria , James Clark , llvm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:46:06 -0700 (PDT) On Sun, Oct 8, 2023 at 10:41=E2=80=AFPM Namhyung Kim = wrote: > > On Thu, Oct 5, 2023 at 4:09=E2=80=AFPM Ian Rogers wr= ote: > > > > Fix clang-tidy found potential memory leak and unread value: > > ``` > > tools/perf/util/hisi-ptt.c:108:3: warning: Value stored to 'data_offset= ' is never read [clang-analyzer-deadcode.DeadStores] > > data_offset =3D 0; > > ^ ~ > > tools/perf/util/hisi-ptt.c:108:3: note: Value stored to 'data_offset' i= s never read > > data_offset =3D 0; > > ^ ~ > > tools/perf/util/hisi-ptt.c:112:12: warning: Potential leak of memory po= inted to by 'data' [clang-analyzer-unix.Malloc] > > return -errno; > > ^ > > /usr/include/errno.h:38:18: note: expanded from macro 'errno' > > ^ > > tools/perf/util/hisi-ptt.c:100:15: note: Memory is allocated > > void *data =3D malloc(size); > > ^~~~~~~~~~~~ > > tools/perf/util/hisi-ptt.c:104:6: note: Assuming 'data' is non-null > > if (!data) > > ^~~~~ > > tools/perf/util/hisi-ptt.c:104:2: note: Taking false branch > > if (!data) > > ^ > > tools/perf/util/hisi-ptt.c:107:6: note: Assuming the condition is false > > if (perf_data__is_pipe(session->data)) { > > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > tools/perf/util/hisi-ptt.c:107:2: note: Taking false branch > > if (perf_data__is_pipe(session->data)) { > > ^ > > tools/perf/util/hisi-ptt.c:111:7: note: Assuming the condition is true > > if (data_offset =3D=3D -1) > > ^~~~~~~~~~~~~~~~~ > > tools/perf/util/hisi-ptt.c:111:3: note: Taking true branch > > if (data_offset =3D=3D -1) > > ^ > > tools/perf/util/hisi-ptt.c:112:12: note: Potential leak of memory point= ed to by 'data' > > return -errno; > > ^ > > /usr/include/errno.h:38:18: note: expanded from macro 'errno' > > ``` > > We already have > > https://lore.kernel.org/r/20230930072719.1267784-1-visitorckw@gmail.com Agreed. There is a written to but not read addressed in this one, but I think that is okay to clean up later and to drop this patch. Thanks, Ian > Thanks, > Namhyung > > > > > > Signed-off-by: Ian Rogers > > --- > > tools/perf/util/hisi-ptt.c | 12 ++++++------ > > 1 file changed, 6 insertions(+), 6 deletions(-) > > > > diff --git a/tools/perf/util/hisi-ptt.c b/tools/perf/util/hisi-ptt.c > > index 45b614bb73bf..ea297329c526 100644 > > --- a/tools/perf/util/hisi-ptt.c > > +++ b/tools/perf/util/hisi-ptt.c > > @@ -98,18 +98,18 @@ static int hisi_ptt_process_auxtrace_event(struct p= erf_session *session, > > int fd =3D perf_data__fd(session->data); > > int size =3D event->auxtrace.size; > > void *data =3D malloc(size); > > - off_t data_offset; > > int err; > > > > if (!data) > > return -errno; > > > > - if (perf_data__is_pipe(session->data)) { > > - data_offset =3D 0; > > - } else { > > - data_offset =3D lseek(fd, 0, SEEK_CUR); > > - if (data_offset =3D=3D -1) > > + if (!perf_data__is_pipe(session->data)) { > > + off_t data_offset =3D lseek(fd, 0, SEEK_CUR); > > + > > + if (data_offset =3D=3D -1) { > > + free(data); > > return -errno; > > + } > > } > > > > err =3D readn(fd, data, size); > > -- > > 2.42.0.609.gbb76f46606-goog > >