Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1680717pxb; Wed, 9 Feb 2022 02:02:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJx9We6UMr12MLsBgJIsoPfYbGU74IGlB+CJuHLugt9kzkuv7IbILHb0v7PnGry49pVQD8lk X-Received: by 2002:a17:902:b184:: with SMTP id s4mr1313055plr.7.1644400950963; Wed, 09 Feb 2022 02:02:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644400950; cv=none; d=google.com; s=arc-20160816; b=f5ixjWg2mOL64Jq6BQaot2BW34w4QDLKcEH5SLFKdIOr6jhaXetg8Ll2uMgQdczkr3 oIeWqMpIkbiRpKpiSXx0nFsMGZFBqM5RPnTaTzvOlpsBHe+LXud5rweW0UmJJWFGM9/K jjtKjaq98Dx8nZTHJUb6f2K111O0UMhVGdwSsK3WMNep/Usy6gwPaZtcqiBj8UlyRBW/ x3CVVG0O/VJzX03Hg7sqZmD22nJ2DUbLgDF0rA5xllNltx3VGnXeMNW/7eHgbHdspLCP PA1OQAdcEkbCBc5xYYU7/ovGBPh3xyBAUwhb2P1weM0uEcnDcuqpbGDx/aiqqy4Ipg4y SVbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XFQAzLxOKup0T8+iPotFxJhknsSgPfAqpuZfKdHLscg=; b=krlt2xVbeiqVqJzgnNS1/WFHqV+7TQlynDj9SU95c4OTP7XDPES/4/heiUKUqZd0tf T/2D5uaARy/vwLlo3Pki1CaDQ15y/fHmG9s4zBAAzMRGli2zRPy49FPOKKfS4h8AFwjb VWOWT5r2932yoIo7XB38ffJIPbbXFdNUTYoOzxXZTiT1vRYxXz+9UACVV3fPKByqYALv c29jK4UdhEh6arzbSJla6TNkvVDdbPWkz2Cm55u2WBjI905GZLYK2y+MhW8WNyx/30wc z7UFZlSCgStyho7ZPiNpQFVT9eA8ooY+GaaWOuYwZBgHAKOq1OUXJc6l86ccI+V7P/Bp ezSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="n/buLgWi"; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y7si15699930pfi.78.2022.02.09.02.02.17; Wed, 09 Feb 2022 02:02:30 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b="n/buLgWi"; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389673AbiBGLun (ORCPT + 99 others); Mon, 7 Feb 2022 06:50:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384862AbiBGLaZ (ORCPT ); Mon, 7 Feb 2022 06:30:25 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFF46C03CA4A; Mon, 7 Feb 2022 03:28:42 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 08BD66077B; Mon, 7 Feb 2022 11:28:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFBAFC340F1; Mon, 7 Feb 2022 11:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644233321; bh=D1iJwyfsHLPr5Rqzs8UxZzRupRZ+cg/8d6hqnSL8FKo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n/buLgWiw/FS/tztTRImwJpwLkPd6pp65n2AJGtT1ZmHl1vKjrS1fCOVL4mDVPTyC dYlUUl6syHS63Tl6RBbiwxAmDzmcgzuCdYzSX8sEXtty42qpTcF5AvisArZp7pRibg NMXv10V1npBZrwqAo9XEPRpM7ktav+0iG342GcdM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dennis Dalessandro , Mike Marciniszyn , Jason Gunthorpe Subject: [PATCH 5.15 054/110] IB/hfi1: Fix tstats alloc and dealloc Date: Mon, 7 Feb 2022 12:06:27 +0100 Message-Id: <20220207103804.114482943@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103802.280120990@linuxfoundation.org> References: <20220207103802.280120990@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mike Marciniszyn commit e5cce44aff3be9ad2cd52f63f35edbd706181d50 upstream. The tstats allocation is done in the accelerated ndo_init function but the allocation is not tested to succeed. The deallocation is not done in the accelerated ndo_uninit function. Resolve issues by testing for an allocation failure and adding the free_percpu in the uninit function. Fixes: aa0616a9bd52 ("IB/hfi1: switch to core handling of rx/tx byte/packet counters") Link: https://lore.kernel.org/r/1642287756-182313-5-git-send-email-mike.marciniszyn@cornelisnetworks.com Reviewed-by: Dennis Dalessandro Signed-off-by: Mike Marciniszyn Signed-off-by: Jason Gunthorpe Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/hw/hfi1/ipoib_main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) --- a/drivers/infiniband/hw/hfi1/ipoib_main.c +++ b/drivers/infiniband/hw/hfi1/ipoib_main.c @@ -22,26 +22,35 @@ static int hfi1_ipoib_dev_init(struct ne int ret; dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats); + if (!dev->tstats) + return -ENOMEM; ret = priv->netdev_ops->ndo_init(dev); if (ret) - return ret; + goto out_ret; ret = hfi1_netdev_add_data(priv->dd, qpn_from_mac(priv->netdev->dev_addr), dev); if (ret < 0) { priv->netdev_ops->ndo_uninit(dev); - return ret; + goto out_ret; } return 0; +out_ret: + free_percpu(dev->tstats); + dev->tstats = NULL; + return ret; } static void hfi1_ipoib_dev_uninit(struct net_device *dev) { struct hfi1_ipoib_dev_priv *priv = hfi1_ipoib_priv(dev); + free_percpu(dev->tstats); + dev->tstats = NULL; + hfi1_netdev_remove_data(priv->dd, qpn_from_mac(priv->netdev->dev_addr)); priv->netdev_ops->ndo_uninit(dev); @@ -166,6 +175,7 @@ static void hfi1_ipoib_netdev_dtor(struc hfi1_ipoib_rxq_deinit(priv->netdev); free_percpu(dev->tstats); + dev->tstats = NULL; } static void hfi1_ipoib_set_id(struct net_device *dev, int id)