Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1367631ybg; Thu, 11 Jun 2020 08:05:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzemdBXm6VZavejuEap8gBdeHDYbaUikWMiIpE4p49tk+TVdbgtewVCvpqKyhYluRfaRRBd X-Received: by 2002:aa7:c558:: with SMTP id s24mr7046823edr.237.1591887929208; Thu, 11 Jun 2020 08:05:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591887929; cv=none; d=google.com; s=arc-20160816; b=tQHzoMLuMcUWSL42d2pKFid61jeyvSlIML72fAbHaldx1XkhLhrB8Qpdve/WWPeDUk 7PawnELNYX9TChtp+LiV6juvyrCAxO52e4bn6gCUZgFEcZEtqkPBDm3s38QIK3UQdrGX ueNQLNac24J2BjFpJsSg+CGCkTaWhJ+IINhJQavPLT/s+Ixkat1qqffcLeR7dbYvCDjl BQ3/So6sSjhT+qCL8oo+KHMeTAmRI+PAQ9JOSRvr8PrdEYvTnk17hD1ZBnrMckxR1bOV fdYPy/EFGD9FLJz4fvAAzHjRXjszV2WXhUeUA/g8WDJBiX7DBtjJByw3bMlwjJ4A35fA HLoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:to:from :dkim-signature; bh=r0hNAlb8gwk+2s8vLxqGkBolOrtvmVp5BagPwVX1Ajk=; b=KaPNtcun6tgV/UMZbd2WpGTEpm5Hv7KgN9V/aruCG1wgCYxHO3z9abk10+PgPI39jy hM8nO9r9ql1s/ojLFI97iqeTb3iE9JSv8PeUG7b/woPZvgIa4qo0K3/bLZDjq74K10Nr P40maBlkCfjwK75HpS1AYoOolOUiuCESi7H2o+jxKg5tF9KKncyU9kZ4bVSkQ6eVbiUV K1qdf4kTgIth9maQVqMUrMKm6emV0mWPT59FpW/4bbi5+TEGJjeIQUdkRyipA3W3cs42 Dv6D1K66Zrzd4qKhPRgmmmxTpnD5JVtogx0UuH1ezLpyLLGFAXU5c1nb+yx93Fe/yfOg ZAmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZEnqBpV6; 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 bu16si1717492edb.146.2020.06.11.08.04.59; Thu, 11 Jun 2020 08:05:29 -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=ZEnqBpV6; 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 S1728430AbgFKPCi (ORCPT + 99 others); Thu, 11 Jun 2020 11:02:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728273AbgFKPCh (ORCPT ); Thu, 11 Jun 2020 11:02:37 -0400 Received: from mail-qv1-xf44.google.com (mail-qv1-xf44.google.com [IPv6:2607:f8b0:4864:20::f44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BC6EC08C5C1; Thu, 11 Jun 2020 08:02:37 -0700 (PDT) Received: by mail-qv1-xf44.google.com with SMTP id er17so2755575qvb.8; Thu, 11 Jun 2020 08:02:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=r0hNAlb8gwk+2s8vLxqGkBolOrtvmVp5BagPwVX1Ajk=; b=ZEnqBpV6x9tbdnOXrWgmoMoqpMcm7FzfGEskyPDedCcKDSQrsF1vEAxEx9ndKxbWHn jS17XPJiB9YI1TnrV5zGnhtH5ObaNDQ3I4vVq8QLarWla8zcjHw4zwGELtxndGQOwjH0 SyYu47PN7bk5ooMJ3JhCYhDB5F8UESAwIAuQbkTRpu6xdomvxWEwTxSqNz2ARGfIfk00 7nMgwDnjIrThaEtNn/LPqSkJVIXO9Vx0qpjKRBnYmNqQSBNCc/+5vgHicWxPXQu6qh/s 5UdV1sorpqq+5yC5X116GTcMYS2IrTvZC1JKINbuGVo9vB+BW/lmgdlTi4aVQZUcZ1Xf 6BTw== 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; bh=r0hNAlb8gwk+2s8vLxqGkBolOrtvmVp5BagPwVX1Ajk=; b=QXQ0Y5/4O+C1igi4p0hkKxFPyn9uH44BL0vh9NuHwI8RtIybeMoGOQP9nyQE0waXC1 gB5Ud2m6NXx/wwiSBqxYsE6GYMiiAaxKiUDFW6PXvxfKic2/H0gjIjr6fv7pVBLbgZjz HRC6uMZSmx2EiFO+toWdSODimC7xCp7IXOp/zTdN5X4vL5gBqp8j0PoOFBPYY1lljCj2 Bw2PSJIgvYWUtLlVHIbuuq457H5cRm/Qs7vA64D2VTLuXNfJacWxvOJNGu6ciZU9FC7u brGK/FSvXq0Eo9F6WrWDazDyEkmPRdr3h30W5pKSsFnac8sSC/StNKaxusvJwaib+IaQ zBvA== X-Gm-Message-State: AOAM530u01gU/T8u/S8df7zqWFPKk8zwLoqZkMCIBBMZnu3RwGzWMice mMV72hMwo3UEHAChQd2JTrg= X-Received: by 2002:ad4:4e14:: with SMTP id dl20mr8503813qvb.101.1591887756824; Thu, 11 Jun 2020 08:02:36 -0700 (PDT) Received: from linux.home ([2604:2000:1344:41d:f00a:33d2:6ec2:475c]) by smtp.googlemail.com with ESMTPSA id 78sm2230157qkg.65.2020.06.11.08.02.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 08:02:35 -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 11:02:21 -0400 Message-Id: <20200611150221.15665-1-gaurav1086@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replace malloc/memset with calloc 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