Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1234009imm; Tue, 5 Jun 2018 11:06:09 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLLmgukv9WI+ArgX52DDLaiwddfTHiYpV91Htx5EZaIKy6Bg/ST/4Z7NwflgUaDIhxaElc4 X-Received: by 2002:a17:902:784d:: with SMTP id e13-v6mr11722497pln.197.1528221969750; Tue, 05 Jun 2018 11:06:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528221969; cv=none; d=google.com; s=arc-20160816; b=hqq25URbVoS+SCnHcaepIjcEdoOr4hMir+On8z6DFncUvpA7cLNq49hC15yzJ6l/o5 viCeiCGNJstN6M1VkRp/FUJBVelcZuSWnjBxW11XelTlFd33cOxuVAcGfxUP1ps3CZyZ 1/IX3idTNJC6GDYc6kU+MUgT2lBmhHFd0yL3vZLVS4CNNsvDrSgv7RNn6P8mJimKisri BXsRzD19cDm//2htDTaRILZZpBfCWePfRV7qKziGa2jt6vUYN4Nw+vFqLxJ3U1WUvR9h 3erw+cG3IrQzXLkp7+2Hvk9yQLvTt4GtNrn2woyF/2AUSaUgm8ZT9Zr3z9J3BMv5k9O+ wh7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=1SheB0y2BTX+uOQy6G3xc44V6QiszxbYrOrU8+vPH0c=; b=ZKhFtWFsA5ae1Z+4p0oJe8TB8wH01MELKlsVsH0rtnLI2ZUF3L3ynsAlgdPzAvFYUU NQCu9VFpltn73QW5zFkJIkQ7RflkkNdmiP1bJDGu9MqedMDKPidt4q37UDbbfUTTVscX GHV72S6YtSQvsDhQa2Wocel/daAA62WITtignSVF5UDbWWVqQkfT38H6WIznYlTzEcu4 96ygQ573Ndlzca4JAi0qadw6Y8sOO8PcCxyi/NunRxJG9yZY98aaT4iy6Wx0TUVxxmEF +w/c0NOnvb/xZ53DaohCFFsht9M7b76XXyc0CeEosZUUdkvaAd5q+49isR/9IJ0CL2vQ xj7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jaS11iQl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id p4-v6si10302971pfg.329.2018.06.05.11.05.54; Tue, 05 Jun 2018 11:06:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jaS11iQl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1752638AbeFESFY (ORCPT + 99 others); Tue, 5 Jun 2018 14:05:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:45646 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752133AbeFERvJ (ORCPT ); Tue, 5 Jun 2018 13:51:09 -0400 Received: from jouet.infradead.org (unknown [179.97.41.186]) (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 356F82083C; Tue, 5 Jun 2018 17:51:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1528221068; bh=QqutBM2Q1YMZxvKrwQXYZjM+P0VYrb5z96fso3dHu6Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jaS11iQlfdrpzK5f3zxCXGt+9IJk2NgQdIoUuVWV9QBzFms010J7Y6CATFMmOWHDd sLx7AGNYFf++2UrIlFkg/EILkqO6cIS2SXl4wfp2v0tPj7ADpDliK7aW3UiFJxyEEY Gspiu+sO3GdnaOpLSW7emM412O7k52cTUWcjqQp0= From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Adrian Hunter , David Ahern , Jiri Olsa , Namhyung Kim , Wang Nan Subject: [PATCH 09/46] perf annotate: Introduce annotated_source__alloc_histograms Date: Tue, 5 Jun 2018 14:49:53 -0300 Message-Id: <20180605175030.32549-10-acme@kernel.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180605175030.32549-1-acme@kernel.org> References: <20180605175030.32549-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnaldo Carvalho de Melo So that we can call it independently, in contexts were we know we already have notes->src allocated. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: https://lkml.kernel.org/n/tip-f5fn7tr1asey6g013wavpn4c@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index f6c9bb29ac84..a6fa49bf879b 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -697,10 +697,9 @@ static void annotated_source__delete(struct annotated_source *src) free(src); } -int symbol__alloc_hist(struct symbol *sym) +static int annotated_source__alloc_histograms(struct annotated_source *src, + size_t size, int nr_hists) { - struct annotation *notes = symbol__annotation(sym); - size_t size = symbol__size(sym); size_t sizeof_sym_hist; /* @@ -720,20 +719,29 @@ int symbol__alloc_hist(struct symbol *sym) sizeof_sym_hist = (sizeof(struct sym_hist) + size * sizeof(struct sym_hist_entry)); /* Check for overflow in zalloc argument */ - if (sizeof_sym_hist > SIZE_MAX / symbol_conf.nr_events) + if (sizeof_sym_hist > SIZE_MAX / nr_hists) return -1; + src->sizeof_sym_hist = sizeof_sym_hist; + src->nr_histograms = nr_hists; + src->histograms = calloc(nr_hists, sizeof_sym_hist) ; + return src->histograms ? 0 : -1; +} + +int symbol__alloc_hist(struct symbol *sym) +{ + size_t size = symbol__size(sym); + struct annotation *notes = symbol__annotation(sym); + notes->src = annotated_source__new(); if (notes->src == NULL) return -1; - notes->src->histograms = calloc(symbol_conf.nr_events, sizeof_sym_hist); - if (notes->src->histograms == NULL) { + + if (annotated_source__alloc_histograms(notes->src, size, symbol_conf.nr_events) < 0) { annotated_source__delete(notes->src); notes->src = NULL; return -1; } - notes->src->sizeof_sym_hist = sizeof_sym_hist; - notes->src->nr_histograms = symbol_conf.nr_events; return 0; } -- 2.14.3