From patchwork Mon Feb 4 21:17:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10796641 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B12806C2 for ; Mon, 4 Feb 2019 21:18:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FB8C2B1EB for ; Mon, 4 Feb 2019 21:18:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 935B92B5B8; Mon, 4 Feb 2019 21:18:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D1402B1EB for ; Mon, 4 Feb 2019 21:18:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729330AbfBDVSC (ORCPT ); Mon, 4 Feb 2019 16:18:02 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:34788 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729224AbfBDVSC (ORCPT ); Mon, 4 Feb 2019 16:18:02 -0500 Received: by mail-pl1-f195.google.com with SMTP id w4so529936plz.1 for ; Mon, 04 Feb 2019 13:18:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/b3usJTzo5aKzuVcaCRq2eC9IV9zhxKKMyiEdMJY9qk=; b=aJbIeZKg8gn8QQls44KitN7xu210Nsn8ilRoZlUdzpdwWXpsUAZihfLZCKNMoWt0+9 AfDQcxGPtTVbeJvitFzQWywkfJ6H/ERP9LL74hPX0JVGy34gBW7Z7s4GBddKjqKb976J VaoKTUGc8pResHPxK9g9XuE+6cVPBTeuatDQ1QUGJ2X7BdJmVq/sERkornVYh9hwYOJQ l1nk9691iTpM81jfxxSNSP5RirPpl35Ng3caql+kH3Lz0gucR+r8fL9VnZuVaaA0qnd5 9o71MiNf5rTVvrRac+UAZdfcNxrYIIV97oCqY3UUbXazw16/9iTiBHmhjvnKDcPdHOvM cTcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/b3usJTzo5aKzuVcaCRq2eC9IV9zhxKKMyiEdMJY9qk=; b=gXCO/VdoKEjHCVJyNwQlZvFPH7NG4GAk+jFBdvoo82dQSwPUq0SNbdF9mRh4fKbtAK 9gIXinUlfICHYhUJAQsqDhMjYCeSTlVWe1Ld8l5yXM2SVEk0cwA4Ef2VvbXtJq3wTbfB n77MQ3mCf756Qp0/MRDLj4hpMkHBqh93OPsBvucIRSQr3b79uTsqGucIAWeD7svFu87P wPBU50qNjd3o0ER7Lqw84m455wbQlP0UMg1tEWS+ElxzHHolqvZydgKai14HFkfTawDO BfcRzy+k1qj0z2kSm5ky1956cp125yioTd4gAJ9Kv5ERMfwvbA8mLfqbfQqd/sqkhM7x xtNw== X-Gm-Message-State: AHQUAub2C+lBKN0m/PDD0YnIWq2tJO3lHMTOL6RB/wCHn4wrUN99IuDG jScpmiM56A/qBWVs4i91nrHGLwmRa+I= X-Google-Smtp-Source: AHgI3Ib5PCU9vavetpYA46FZLiI7MGGeRldXEA08ah6l3AKy23Hm6kIkDb3eyUeGKk75p8Rdr0qrig== X-Received: by 2002:a17:902:7892:: with SMTP id q18mr1433967pll.217.1549315081555; Mon, 04 Feb 2019 13:18:01 -0800 (PST) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id o189sm1496673pfg.117.2019.02.04.13.17.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Feb 2019 13:18:00 -0800 (PST) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1gqlct-0005KT-E0; Mon, 04 Feb 2019 14:17:59 -0700 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe Subject: [PATCH 3/8] RDMA/device: Call ib_cache_release_one() only from ib_device_release() Date: Mon, 4 Feb 2019 14:17:46 -0700 Message-Id: <20190204211751.19001-4-jgg@ziepe.ca> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190204211751.19001-1-jgg@ziepe.ca> References: <20190204211751.19001-1-jgg@ziepe.ca> MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jason Gunthorpe Instead of complicated logic about when this memory is freed, always free it during device release(). All the cache pointers start out as NULL, so it is safe to call this before the cache is initialized. This makes for a simpler error unwind flow, and a simpler understanding of the lifetime of the memory allocations inside the struct ib_device. Signed-off-by: Jason Gunthorpe --- drivers/infiniband/core/cache.c | 3 +++ drivers/infiniband/core/device.c | 41 ++++++++++---------------------- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/drivers/infiniband/core/cache.c b/drivers/infiniband/core/cache.c index 7b04590f307f52..2338d0b3a0cab8 100644 --- a/drivers/infiniband/core/cache.c +++ b/drivers/infiniband/core/cache.c @@ -1460,6 +1460,9 @@ void ib_cache_release_one(struct ib_device *device) { int p; + if (!device->cache.ports) + return; + /* * The release function frees all the cache elements. * This function should be called as part of freeing diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index b21ea9154cf24d..286a41cd4cda78 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -244,17 +244,10 @@ static void ib_device_release(struct device *device) struct ib_device *dev = container_of(device, struct ib_device, dev); WARN_ON(dev->reg_state == IB_DEV_REGISTERED); - if (dev->reg_state == IB_DEV_UNREGISTERED) { - /* - * In IB_DEV_UNINITIALIZED state, cache or port table - * is not even created. Free cache and port table only when - * device reaches UNREGISTERED state. - */ - ib_cache_release_one(dev); - kfree(dev->port_immutable); - } + ib_cache_release_one(dev); ib_security_release_port_pkey_list(dev); kfree(dev->port_pkey_list); + kfree(dev->port_immutable); kfree(dev); } @@ -519,13 +512,6 @@ static void setup_dma_device(struct ib_device *device) } } -static void cleanup_device(struct ib_device *device) -{ - ib_cache_cleanup_one(device); - ib_cache_release_one(device); - kfree(device->port_immutable); -} - static int setup_device(struct ib_device *device) { struct ib_udata uhw = {.outlen = 0, .inlen = 0}; @@ -547,26 +533,16 @@ static int setup_device(struct ib_device *device) if (ret) { dev_warn(&device->dev, "Couldn't query the device attributes\n"); - goto port_cleanup; + return ret; } ret = setup_port_pkey_list(device); if (ret) { dev_warn(&device->dev, "Couldn't create per port_pkey_list\n"); - goto port_cleanup; - } - - ret = ib_cache_setup_one(device); - if (ret) { - dev_warn(&device->dev, - "Couldn't set up InfiniBand P_Key/GID cache\n"); return ret; } - return 0; -port_cleanup: - kfree(device->port_immutable); - return ret; + return 0; } /** @@ -606,6 +582,13 @@ int ib_register_device(struct ib_device *device, const char *name) if (ret) goto out; + ret = ib_cache_setup_one(device); + if (ret) { + dev_warn(&device->dev, + "Couldn't set up InfiniBand P_Key/GID cache\n"); + goto out; + } + device->index = __dev_new_index(); ib_device_register_rdmacg(device); @@ -632,7 +615,7 @@ int ib_register_device(struct ib_device *device, const char *name) cg_cleanup: ib_device_unregister_rdmacg(device); - cleanup_device(device); + ib_cache_cleanup_one(device); out: mutex_unlock(&device_mutex); return ret;