From patchwork Thu Feb 29 06:20:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 208209 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp205665dyb; Wed, 28 Feb 2024 22:22:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUR8DJOKtmek6wqG0hpxw1ws33vpR0yDYcOmop9bV9gSLAMTVFk6iBoLDeiaK7dpgmQVgr2NaWqqlDV4UpRJwEkgr5v4Q== X-Google-Smtp-Source: AGHT+IFCR7CSkxmfVuNgKH55iD6NUITIEE7d+B4M3z1Lgr46pFDjR5hskXy/LxuMcFPxoei7Ls95 X-Received: by 2002:a05:6a20:d045:b0:1a0:f6ea:f423 with SMTP id hv5-20020a056a20d04500b001a0f6eaf423mr1682443pzb.6.1709187724820; Wed, 28 Feb 2024 22:22:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709187724; cv=pass; d=google.com; s=arc-20160816; b=bn2mOcVWhc9T1asZ6I8eQCNdBNUHWZrtRviScQMAJvjjpwo11gcl1S0iOuEmyugPss swqftqkjFbdiai49XL0x9f0KUXEPeYsUJ3dGdnMxqOg7HzQoBZJmKipYVSJmvF13qkp6 HA34d7crRWgTU+KDfYXee72FNI/rqm4g2iAqdUNniL/FvlcvUe04pjOzC2iOt1kqNG4p 75aVolBs6h4/vAx6v6GbR4wnSzXF//l9A8nEaA/e3vkJZBwlVnOV/Jbi2SDVYT1TJdZH UgbZ1slIPAV0PbbQ+zXeh284XkcV3SzIX2Ikqm9zhwt7F8JAI+Wu7KyqWxPyW9efgBIL bBcQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:date:dkim-signature; bh=HP7FHTSIsiaJThzWBkYLUGihLpdmeLYVXFRi2ap+AOo=; fh=TdLTyXh0iXrIRZcB+/oJtX1a/0Zxu6NsGqy2yog7XTw=; b=PgROEtkgPOWWdrdKflmaF7TjlFybePhWfoMq/h3CuSChtqjkF0syHnU9XyVsKOZ4iE z5AgypOER4JU+ECk/w08jjoGkthVbdnclYOwxGxkp+fWQdbvnntP9Ja4I6n3D5MrfLk2 bJJ+i9oTfhLu839ADT1Ba5XroDiyXddbFZpcNYXymfqggoxjDFHO+U0F0jJHW0bfVAiJ 4mVc7eUDDsul6z57FqU3LxfZIusRsnvJe0OcETNBqZnpkMjlmEL6/pv4qAPp/EwsOCy/ IDHkz/uVDJ1mQjG8M3/ZsAcLnGqxZzk1MzDytKX0mtqlM4BosB2DNtzVyVplSDOrP71z eoZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Q93PgiMu; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-86162-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86162-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id me7-20020a17090b17c700b0029a8a9a1f6bsi911096pjb.1.2024.02.28.22.22.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 22:22:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-86162-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Q93PgiMu; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-86162-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86162-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 25FA4283CE4 for ; Thu, 29 Feb 2024 06:21:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 831F23DBB7; Thu, 29 Feb 2024 06:21:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Q93PgiMu" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A9C136AE1 for ; Thu, 29 Feb 2024 06:21:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709187664; cv=none; b=JxEmqH0Wr0reLBzqN7DmqiWkHBxR7ut9xvu6H4n5ww8euwYnwO3h43ZCldtonHfcSKU6dC+aqUb0wAgqMSY5iwK7oWoxZmRq8ewCCTbwbEYx0+IJaIso1j78XdCwss6ZnTOKUwgjJE52AVfJkZim8J3kZcLU0P6B4SX+kS0ERpo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709187664; c=relaxed/simple; bh=rWfMlMwr/8u2RrDewjX8624dpgZQiC94SLvycpO6+Tk=; h=Date:Message-Id:Mime-Version:Subject:From:To:Content-Type; b=odCwG8ayQc5zqiKwm/zUsZWaFPzLbDchJNsEhtYqvA1wurq25VpEpWw/mDnbAgenT+GRIfFLmb0sSPdlHiwrf8i91HFI57f2/9ahGJGiwatO7Q7uqLgpDZzyuv8wRzWtIzCs3sZUaG8rxfv8lkH8xQL4ek7f7T7QK5MT4KilN+0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Q93PgiMu; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dcc4563611cso1060677276.3 for ; Wed, 28 Feb 2024 22:21:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709187662; x=1709792462; darn=vger.kernel.org; h=to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=HP7FHTSIsiaJThzWBkYLUGihLpdmeLYVXFRi2ap+AOo=; b=Q93PgiMuTNFHaFBMTT7q9IYkbqBn6uQBFPZFiRtHrLrnA3s4/gYDUZBLgjduFT37rP NPWumPy5yNM+/K56ZIBF9ll3YYvsmm9zsX5q3+Fj67Z78eyewYvmWlA4gjNebUhOdRbz BxwfYAxh/GocDQXt+oIsFPP5Eu1TbzBSFkKlIb7XAh0E2XZvPR+PgbAPXqn4uxpXVyAB tVcEORGj0cEEtexjZTsWJnMmhG4GL2PGlq+bSSUEZ9MgRJwR3tkMnFliXSAMMu5jRhBu b6rLBUQuZowiUqqik9g3H8nrYBSU6WBX/47YDnrFmrkEOQ3oin1abYzOJ9Ezp6UyTO9p LLJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709187662; x=1709792462; h=to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=HP7FHTSIsiaJThzWBkYLUGihLpdmeLYVXFRi2ap+AOo=; b=n/vQPj76WOQW7aJU5obSS2w54WGnPH/PFlJj+MCeDFRrDV5PjIA1MaWsH75E97gUwR GOUjlr6IFf8+RD25KZ3aUoQQyfxNajj1xBYWjz+2uzQbuFO72bNA0KIzhL7yPTxqlLSL 3y5PcGC+q9vklJTHQxXIKpVZjqntWPrUaeninZFEOfK5qeRNSHE9KyoIIJHv7Sje9rwL BkJ0Y6g4ZDFMIY0JDvbjbZeDpACi7NT3KwMPkrLzUpngKgY++4hyC26lUjtbYHGqWXgB TNLKSZHa8zsH5644ivtALcBI6KJPxSitpBY4NNxIU+eae0B6B5RoSN52Cnu/WYlQWkGC ReUw== X-Forwarded-Encrypted: i=1; AJvYcCWItcyCMxBUmHLjnSd72kDrZQzN7KR+ye5GAQsThPrqLmNU5T5sHmzZRhP3w+l0ufLJnm2CF24LVb1B8yIoccNSzAw7OzxcvfjbOiVn X-Gm-Message-State: AOJu0Yy7ZckTAa8WlyPgNQ+ufWbi3M9Kp1fVUfPxdfXy8eNJl/5uHDPg kbgLtD2Wj+3YDgAuKgFgk9ejIED8k1o5LMNX3PCTp4DjhROfuUZ+V+QKMEoqZXtQv5p0jdQsSn9 Axws1Xg== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:77dc:144c:334e:e2dd]) (user=irogers job=sendgmr) by 2002:a05:6902:188d:b0:dcc:54d0:85e0 with SMTP id cj13-20020a056902188d00b00dcc54d085e0mr369155ybb.11.1709187662515; Wed, 28 Feb 2024 22:21:02 -0800 (PST) Date: Wed, 28 Feb 2024 22:20:48 -0800 Message-Id: <20240229062048.558799-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1] perf map: Fix map reference count issues From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Masami Hiramatsu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792213227938886869 X-GMAIL-MSGID: 1792213227938886869 The find will get the map, ensure puts are done on all paths. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/maps.c | 14 +++++++------- tools/perf/util/probe-event.c | 4 +--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c index 53aea6d2ef93..ce13145a9f8e 100644 --- a/tools/perf/util/maps.c +++ b/tools/perf/util/maps.c @@ -611,14 +611,14 @@ struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp) struct symbol *result = NULL; /* Ensure map is loaded before using map->map_ip */ - if (map != NULL && map__load(map) >= 0) { - if (mapp) - *mapp = map; - + if (map != NULL && map__load(map) >= 0) result = map__find_symbol(map, map__map_ip(map, addr)); - if (!mapp) - map__put(map); - } + + if (mapp) + *mapp = map; + else + map__put(map); + return result; } diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index be71abe8b9b0..2a0ad9ecf0a2 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -2274,9 +2274,7 @@ static int find_perf_probe_point_from_map(struct probe_trace_point *tp, ret = pp->function ? 0 : -ENOMEM; out: - if (map && !is_kprobe) { - map__put(map); - } + map__put(map); return ret; }