Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp74776ybg; Thu, 11 Jun 2020 17:39:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+ho27Zrs8YkW5MuvPUnVeWaw0lQtsINnVwK95ld8TFaH8wx7N18wbTS06T+K8OUdK05WE X-Received: by 2002:a17:906:3e15:: with SMTP id k21mr11452512eji.525.1591922340993; Thu, 11 Jun 2020 17:39:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591922340; cv=none; d=google.com; s=arc-20160816; b=rtl0+rveAnA0nXkbW3/BwUjp84deSyE5CF4LeCwv0TqVzLmxgybd80/puIOde8jsY6 UG+WK88sAnDdlKPn0Ylcr/f2syTqOH8yb3u9tZIyPeLZqxaqDsMIVrV5WG3LYE0OdIWr f0/fm7Z9Yl87tgE1gbrJzF41EVwO2k88DKQxhBngpY+eEIhchqXuAq3qA0akO4gZ+4z9 tnXVR5YISHLZXHVoYf9YfQlc5emQSD4wxePlNGT5tvuw6T4WLuC5B3romU2+lfTVYK6L EtGaQ2ErjKuTE14C+jW8wFOya0T9v16rfS7zZsvHKLZFIQNiRl/DNfNWXu79UnmfWNEK pVoQ== 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:to:from:dkim-signature; bh=boR49jpVVRV/Q0WW/lSHnRqxWQvt+zi1RK7D2cfa/KQ=; b=Y0ufSEAT6K1p57jYmatWbMv/kAjLow7KSoznBtwmi//2pNxWEJf2kFZBhb6pG3EioJ bOM0E+Oal1oMoFrnzCfRstioL18Mr4G/o7h/zCD2RaP/uWA+k+snHnmrN8PuyTr/mI0n RlJiFcJ+ZCj5bOHrY2hMp5Y5KibTnN2lWM1JcanmFUwrNnVn/sq9zvza+lsSXyfT1/Z8 Ao8D9cU1NQ0clQkkM7Ho7c8Oiorh+JL2ttUoWAJab2XHx+M7zTnwFNk3EFvAdn23ZpSp dkbWDMBc/tYqnQFp+iQkPbceYOiBAFHmyuSzsJdxzY7PWrhXs8m6xJAeJOJjdYWIgYij bQxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rlAdwRm9; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d4si2821652ejw.326.2020.06.11.17.38.38; Thu, 11 Jun 2020 17:39: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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rlAdwRm9; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726385AbgFLAgu (ORCPT + 99 others); Thu, 11 Jun 2020 20:36:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726321AbgFLAgt (ORCPT ); Thu, 11 Jun 2020 20:36:49 -0400 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C815C03E96F; Thu, 11 Jun 2020 17:36:49 -0700 (PDT) Received: by mail-qt1-x843.google.com with SMTP id c12so5927705qtq.11; Thu, 11 Jun 2020 17:36:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=boR49jpVVRV/Q0WW/lSHnRqxWQvt+zi1RK7D2cfa/KQ=; b=rlAdwRm9hTb9aJanRInl8J1ga3yBiPstojKvPwkWPLmWuhIfnagqRf2036p2pa7Q8A RWu+NMUefznT+bPIVBlAfmv7d5vyOOipVD8HsRVHKtu06OL3V2c11fgP/8QE4emjSNtD 33wi+hHa5G97wharcnrXbgMpWMylPcxvZYMHce+FHT6kEEn98NFDhOfnnwfux1qBHw3H /gfdxPgeGbhjpmsyIK/k/5zOFWMtScvvhasE5yPPAdtTWMvY8sii62idNBcAM3Gl1Zss +km/niDjnK5rAm8UvK6mCLrvTajNjdne/kuTXkXmmxlpvSQB9DNjrw7CeTeljT/V0Xaw cfiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=boR49jpVVRV/Q0WW/lSHnRqxWQvt+zi1RK7D2cfa/KQ=; b=DbAIuxPnZPywXMrpvgd1mxIa6i62Z0S25q8GPxcOmvVht9ATE6CsEI3/Grh6ENWTEm T1LD54yHKoDxWkOuyj64zQAIS0BXWJwttng+RuG2WgFarP2Dbrl/v4paDlfyni0hBbbW KqKRjxntJiXvbtGRYdv+BOswOGXfLue0Q4YxnlCt3lLXtpO4FoNJfZ8lzLu0shn74ulM ypZ28hVQQA+kHvviyjyyzRmf7MYE0CtOcLHtzpWK7w7jZW1qj8lOADzzudet+7glmjOZ R2n1WIrWU0hD+EZP8Y8kWq5a2TePfbqETq5uAXNO5Qj8aUgz92SEEf7iCD8Zr+gajRum 2gPg== X-Gm-Message-State: AOAM531NL+KxMHB3bdPi2zQRRe7Jocvax45yuj4pnuODSuz2Ck6SrVvl L/I2CtffeoQnZs9L4T0rm8s= X-Received: by 2002:ac8:1742:: with SMTP id u2mr641083qtk.341.1591922208515; Thu, 11 Jun 2020 17:36:48 -0700 (PDT) Received: from linux.home ([2604:2000:1344:41d:f00a:33d2:6ec2:475c]) by smtp.googlemail.com with ESMTPSA id m126sm3432996qke.99.2020.06.11.17.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 17:36:48 -0700 (PDT) From: Gaurav Singh To: gaurav1086@gmail.com, Alexei Starovoitov , Daniel Borkmann , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , John Fastabend , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , KP Singh , netdev@vger.kernel.org (open list:XDP (eXpress Data Path)), bpf@vger.kernel.org (open list:XDP (eXpress Data Path)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] xdp_rxq_info_user: Replace malloc/memset w/calloc Date: Thu, 11 Jun 2020 20:36:40 -0400 Message-Id: <20200612003640.16248-1-gaurav1086@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200611150221.15665-1-gaurav1086@gmail.com> References: <20200611150221.15665-1-gaurav1086@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replace malloc/memset with calloc Fixes: 0fca931a6f21 ("samples/bpf: program demonstrating access to xdp_rxq_info") Signed-off-by: Gaurav Singh --- samples/bpf/xdp_rxq_info_user.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/samples/bpf/xdp_rxq_info_user.c b/samples/bpf/xdp_rxq_info_user.c index 4fe47502ebed..caa4e7ffcfc7 100644 --- a/samples/bpf/xdp_rxq_info_user.c +++ b/samples/bpf/xdp_rxq_info_user.c @@ -198,11 +198,8 @@ static struct datarec *alloc_record_per_cpu(void) { unsigned int nr_cpus = bpf_num_possible_cpus(); struct datarec *array; - size_t size; - size = sizeof(struct datarec) * nr_cpus; - array = malloc(size); - memset(array, 0, size); + array = calloc(nr_cpus, sizeof(struct datarec)); if (!array) { fprintf(stderr, "Mem alloc error (nr_cpus:%u)\n", nr_cpus); exit(EXIT_FAIL_MEM); @@ -214,11 +211,8 @@ static struct record *alloc_record_per_rxq(void) { unsigned int nr_rxqs = bpf_map__def(rx_queue_index_map)->max_entries; struct record *array; - size_t size; - size = sizeof(struct record) * nr_rxqs; - array = malloc(size); - memset(array, 0, size); + array = calloc(nr_rxqs, sizeof(struct record)); if (!array) { fprintf(stderr, "Mem alloc error (nr_rxqs:%u)\n", nr_rxqs); exit(EXIT_FAIL_MEM); @@ -232,8 +226,7 @@ static struct stats_record *alloc_stats_record(void) struct stats_record *rec; int i; - rec = malloc(sizeof(*rec)); - memset(rec, 0, sizeof(*rec)); + rec = calloc(1, sizeof(struct stats_record)); if (!rec) { fprintf(stderr, "Mem alloc error\n"); exit(EXIT_FAIL_MEM); -- 2.17.1