Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp1934953ima; Thu, 25 Oct 2018 07:15:15 -0700 (PDT) X-Google-Smtp-Source: AJdET5exCzQdWHjSzdceBjIX77yjTfhAZ8GoWDzy2OXSHcTb5b4hoZnUIQXmTCE5IUfYBrZIn3r2 X-Received: by 2002:a17:902:263:: with SMTP id 90-v6mr1694146plc.190.1540476915240; Thu, 25 Oct 2018 07:15:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540476915; cv=none; d=google.com; s=arc-20160816; b=uawXHWapCRR8fIu/V1gMXUKMkAaqISS6MySp+6pDfYAPekT3KEUYZmA9a2SITOrqgx lrShOcH57KmfSXAKMaoJKvSiThtf39RSlmyM+iZF638De+JuNywFiYTHNUaFxhYyKGTM lnSmCVJRawsjjui4XVRX7nc0vVL0aP191t+WNzU2vycOC1yEBlizJkr09Q1YZvIo6PFc cxXTAnXNQjXcSodKWENnzcqsSrTaatWvIxe90lLwEJwtV3qFc++3Iq7KLSCa+DqcHx7x MrvDs3vmKTTIUXUAr1xgLaq3jtUKsWOzJTCGW9sgw/NeoZgh3ACsRN7hJI2XwJ8gGZLL V0kw== 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; bh=JWzGCxzxFOkj7vX9SUhqe+RfThYpszjJaxcrRtBMnsM=; b=wwHVlcmY7S8jjMDagVhZQcuFTomNMlr9VUAu21oY4JL1HO3vi9khri9wkTVBZa2/dA RClHHU5Uni3AuN+j89YtDXH+BFzMIgmi2arShPbeG0X6mq94F8ALUEGus05hN7ohhDOU EZOqlRFcYQ4ZG++SMSnfmkKA8AxzdpAzYzFDtoZsYp2G9A1LBbrx+UkegONoNme99USy +P4Ajg1KMQZn6wlZgrietrfD1q0TGaZknq1Mz8Ic+n/W4TcBLpKX7Nsc+X3TSOruqelm W+I250o0E6vvGXZAgoiI+g8LAcKXUOPkS7CmJXEfSA59TJNRDrZPqDvfdvoLXkWoQ5Ew H9Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UkwsT0c6; 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 y190-v6si8265247pfy.147.2018.10.25.07.14.40; Thu, 25 Oct 2018 07:15:15 -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=UkwsT0c6; 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 S1727945AbeJYWoE (ORCPT + 99 others); Thu, 25 Oct 2018 18:44:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:52596 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727877AbeJYWoD (ORCPT ); Thu, 25 Oct 2018 18:44:03 -0400 Received: from sasha-vm.mshome.net (unknown [167.98.65.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 78E9C20848; Thu, 25 Oct 2018 14:11:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1540476668; bh=kU97w5KekRBTXyIZX2L7/uyudWsVEHglUkkus9TZBrY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UkwsT0c6prVyVub1kQwnrWBUVIQqgDWFYGrfeTdh6XiGvCIDwqcWBvwL9Kts1d0vZ VJ2EBgQmz5nbIotemgF74LaZpmG1ssN/JWfela/NJ+FBB8nex9VRMtO0hFzYF2hK57 /w2kUYZbS5lR0W9K7WL24C5AgLO+qVrkOb84SmPM= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Doug Ledford , Sasha Levin Subject: [PATCH AUTOSEL 4.14 09/46] IB/rxe: put the pool on allocation failure Date: Thu, 25 Oct 2018 10:10:16 -0400 Message-Id: <20181025141053.213330-9-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025141053.213330-1-sashal@kernel.org> References: <20181025141053.213330-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Doug Ledford [ Upstream commit 6b9f8970cd30929cb6b372fa44fa66da9e59c650 ] If the allocation of elem fails, it is not sufficient to simply check for NULL and return. We need to also put our reference on the pool or else we will leave the pool with a permanent ref count and we will never be able to free it. Fixes: 4831ca9e4a8e ("IB/rxe: check for allocation failure on elem") Suggested-by: Leon Romanovsky Signed-off-by: Doug Ledford Signed-off-by: Sasha Levin --- drivers/infiniband/sw/rxe/rxe_pool.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_pool.c b/drivers/infiniband/sw/rxe/rxe_pool.c index 3b4916680018..b4a8acc7bb7d 100644 --- a/drivers/infiniband/sw/rxe/rxe_pool.c +++ b/drivers/infiniband/sw/rxe/rxe_pool.c @@ -394,23 +394,25 @@ void *rxe_alloc(struct rxe_pool *pool) kref_get(&pool->rxe->ref_cnt); - if (atomic_inc_return(&pool->num_elem) > pool->max_elem) { - atomic_dec(&pool->num_elem); - rxe_dev_put(pool->rxe); - rxe_pool_put(pool); - return NULL; - } + if (atomic_inc_return(&pool->num_elem) > pool->max_elem) + goto out_put_pool; elem = kmem_cache_zalloc(pool_cache(pool), (pool->flags & RXE_POOL_ATOMIC) ? GFP_ATOMIC : GFP_KERNEL); if (!elem) - return NULL; + goto out_put_pool; elem->pool = pool; kref_init(&elem->ref_cnt); return elem; + +out_put_pool: + atomic_dec(&pool->num_elem); + rxe_dev_put(pool->rxe); + rxe_pool_put(pool); + return NULL; } void rxe_elem_release(struct kref *kref) -- 2.17.1