From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3C1D9C4332F for ; Tue, 1 Nov 2022 22:53:52 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id DBE3280BF7; Tue, 1 Nov 2022 22:53:51 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org DBE3280BF7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1667343231; bh=qXyx4EJUKsCC9X85HKWed8VSwajo/+Hd9R6ecv++Mjo=; h=From:To:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=N9Y9JwiQM3VAUMzUk+1wS2fsE5QUxolqEjV/ExOhNBBI2RjZJLby2LG3nhC6lgZOD 7n4Xg4rqgFdiaa1LhevGe1M9AyJoJAK3jswjJJ4pMCNAPAKA/xueTc6GdKMyBOt7nB R6s3/YD4k5WSrPW8OaYJJoE+qqA+haFPUMVVECPZ7ub8xBjEylKMzSrfjYjAaq9yfZ N7LADUPO8/WoTQgJj6GtCHgUHOmeaeJ7WgV/SxwRYB66EBRnVEtMlXkkUIf/HbIfKT 73W5zGFt5yD0Khm4kweOAJIdgw3A7cwfZ6QJUzuMH/NA8qpckayVE0jp+z5c7a/LHR TCSuIbEVLx5/g== X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RHpLCG_HlGph; Tue, 1 Nov 2022 22:53:51 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp1.osuosl.org (Postfix) with ESMTP id E3B1780C20; Tue, 1 Nov 2022 22:53:50 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org E3B1780C20 Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 2ABCB1BF3E8 for ; Tue, 1 Nov 2022 22:53:15 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 97B784074E for ; Tue, 1 Nov 2022 22:53:12 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 97B784074E X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TKIRLJGQmNXe for ; Tue, 1 Nov 2022 22:53:12 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org E9CEA4055A Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by smtp2.osuosl.org (Postfix) with ESMTPS id E9CEA4055A for ; Tue, 1 Nov 2022 22:53:11 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6500,9779,10518"; a="371348117" X-IronPort-AV: E=Sophos;i="5.95,232,1661842800"; d="scan'208";a="371348117" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2022 15:53:10 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10518"; a="723324051" X-IronPort-AV: E=Sophos;i="5.95,232,1661842800"; d="scan'208";a="723324051" Received: from jekeller-desk.amr.corp.intel.com ([10.166.241.7]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2022 15:53:10 -0700 From: Jacob Keller To: Intel Wired LAN Date: Tue, 1 Nov 2022 15:52:36 -0700 Message-Id: <20221101225240.421525-12-jacob.e.keller@intel.com> X-Mailer: git-send-email 2.38.0.83.gd420dda05763 In-Reply-To: <20221101225240.421525-1-jacob.e.keller@intel.com> References: <20221101225240.421525-1-jacob.e.keller@intel.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667343191; x=1698879191; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vj2T2FSJCoTRiyMK2qb+XLgzjMnvzMAFJZBeaQyyxmk=; b=dlPtP+c0If6jXOF0VSVS/8yvzAI2gzy6JkIirJeqeU38yPYEGArFJ5yw gaR+g/0Mk5QjVdpkovHYvMa2ukBSr6BH+OW/A19dz51gs8qnzslOD5DSf 17myRcaaboB0gliz81tqp0P8xU7u2T83euXSQyYwnsIeAhNP2ezrbucuD 13E0YxPfUMIvz5Nl2RSJTKxmUV45Ih/rEflERUrSv5Npd3rr3p+lUG2uK Fw9pmUjEtEiAJHZJ2P0KsvCgoJOoFvgW/WZQPgSnuFa7yLu735O7WWZh2 YEOufbFqG2jTDOOANR74UrQSOGQnOoVyTaQMgfPkUStJ0Z9seDfoFRIWp w==; X-Mailman-Original-Authentication-Results: smtp2.osuosl.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=dlPtP+c0 Subject: [Intel-wired-lan] [PATCH net-next 11/15] ice: cleanup allocations in ice_ptp_alloc_tx_tracker X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" The ice_ptp_alloc_tx_tracker function must allocate the timestamp array and the bitmap for tracking the currently in use indexes. A future change is going to add yet another allocation to this function. If these allocations fail we need to ensure that we properly cleanup and ensure that the pointers in the ice_ptp_tx structure are NULL. Simplify this logic by allocating to local variables first. If any allocation fails, then free everything and exit. Only update the ice_ptp_tx structure if all allocations succeed. This ensures that we have no side effects on the Tx structure unless all allocations have succeeded. Thus, no code will see an invalid pointer and we don't need to re-assign NULL on cleanup. This is safe because kernel "free" functions are designed to be NULL safe and perform no action if passed a NULL pointer. Thus its safe to simply always call kfree or bitmap_free even if one of those pointers was NULL. Signed-off-by: Jacob Keller --- drivers/net/ethernet/intel/ice/ice_ptp.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c index cfc20e430ff5..b5f061580a4a 100644 --- a/drivers/net/ethernet/intel/ice/ice_ptp.c +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c @@ -814,17 +814,22 @@ static bool ice_ptp_tx_tstamp(struct ice_ptp_tx *tx) static int ice_ptp_alloc_tx_tracker(struct ice_ptp_tx *tx) { - tx->tstamps = kcalloc(tx->len, sizeof(*tx->tstamps), GFP_KERNEL); - if (!tx->tstamps) - return -ENOMEM; + struct ice_tx_tstamp *tstamps; + unsigned long *in_use; + + tstamps = kcalloc(tx->len, sizeof(*tstamps), GFP_KERNEL); + in_use = bitmap_zalloc(tx->len, GFP_KERNEL); + + if (!tstamps || !in_use) { + kfree(tstamps); + bitmap_free(in_use); - tx->in_use = bitmap_zalloc(tx->len, GFP_KERNEL); - if (!tx->in_use) { - kfree(tx->tstamps); - tx->tstamps = NULL; return -ENOMEM; } + tx->tstamps = tstamps; + tx->in_use = in_use; + spin_lock_init(&tx->lock); spin_lock(&tx->lock); -- 2.38.0.83.gd420dda05763 _______________________________________________ Intel-wired-lan mailing list Intel-wired-lan@osuosl.org https://lists.osuosl.org/mailman/listinfo/intel-wired-lan