From patchwork Mon Feb 4 21:17:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10796643 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 DDA0713B4 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 CD6882B340 for ; Mon, 4 Feb 2019 21:18:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C042C2B5AE; 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 9AB0D2B340 for ; Mon, 4 Feb 2019 21:18:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729315AbfBDVSB (ORCPT ); Mon, 4 Feb 2019 16:18:01 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:33948 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729224AbfBDVSB (ORCPT ); Mon, 4 Feb 2019 16:18:01 -0500 Received: by mail-pf1-f195.google.com with SMTP id h3so522942pfg.1 for ; Mon, 04 Feb 2019 13:18:01 -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=sbIbpXc5wgxbKoNhEP8faxcehxBYMwXEwY7QhLOqGQY=; b=MpoI0pkauEqd4yUsH82PPVceAzHmbus0aROwHn+3wmV7hwy/LEtj4kcGmcv5XEtm9o OElxUnPkAYD4d0CSdXXl/IFFZ+OIUpEigXshZMiPCDIguODX5T0crBeA4k0xvNzIbIuP /d5687dRjtMG0ZMrFlmfXgRNr0lscDwHfpz05ASc2I/4oIYvP1s+fhq3AWR3vC1S8FEo eX0AWZLWajh5OkIBi/yWUAgorGQEolNSq9GaU8vwiB4+AQO0+eaWFzP5OoqvPiCphpTa 0id195ZtWPQ0Eb5JhuPlx+l+QozjN4KH+RWces8b6wD8TdDm/choigTb6JaKT8c34MNG NRKA== 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=sbIbpXc5wgxbKoNhEP8faxcehxBYMwXEwY7QhLOqGQY=; b=GGjM/9rUko5kycfdq3FAekW2exJSSwIFqkbml09sqDadmlMfR25AaUzGB+UYXXVk8s tIUj2dUmHWDwIClMBKtWL+Ro2kHYy1n7YGlAF89GBR0MQBw6EBGgUTOr2mDf8Qg9Khdu VgKGt2WUUOFcjbb9kBQse0/np4hJgA6r97KH65m1iB14pxsNxNOJD9ijjPRLv0Bfigjc e3PTLJ94ju9CcwxaTAzVKIksOkKQG1CVBXfK96rm1Xj+rOUTFB7dFnvBtlsKLmQUqctW IplYHIzb6cKwd9gH1Jd9zIRvDQUPqExirsR/nkEVCh8v9z2uUSgk1ejCneowpUA8l0F4 vssg== X-Gm-Message-State: AHQUAubjH4aF+j3kE4xqQNlAB5Aiy0vogtRdcKog3OwJmJ6qJ3YGivyQ 58g64MGlj4e45r0RYpcmK6fWnD73z5Y= X-Google-Smtp-Source: AHgI3IZ+QHkpXjYnbSvG/yIBGyIjtcsYdVf6tJUHryX4WPhW6Y9e6nikcfV742c1hVlMA6EtVF4Jsw== X-Received: by 2002:a63:4c07:: with SMTP id z7mr1289321pga.319.1549315080746; Mon, 04 Feb 2019 13:18:00 -0800 (PST) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id o5sm1150165pgm.68.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-0005KH-AZ; Mon, 04 Feb 2019 14:17:59 -0700 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe , Parav Pandit Subject: [PATCH 1/8] RDMA/device: Check that the rename is nop under the lock Date: Mon, 4 Feb 2019 14:17:44 -0700 Message-Id: <20190204211751.19001-2-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 Since another rename could be running in parallel it is safer to check that the name is not changing inside the lock, where we already know the device name will not change. Fixes: d21943dd19b5 ("RDMA/core: Implement IB device rename function") Signed-off-by: Jason Gunthorpe Reviewed-by: Parav Pandit --- drivers/infiniband/core/device.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index 55221990d946b2..f9f33e842c16b6 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -189,12 +189,14 @@ static struct ib_device *__ib_device_get_by_name(const char *name) int ib_device_rename(struct ib_device *ibdev, const char *name) { - int ret = 0; - - if (!strcmp(name, dev_name(&ibdev->dev))) - return ret; + int ret; mutex_lock(&device_mutex); + if (!strcmp(name, dev_name(&ibdev->dev))) { + ret = -EEXIST; + goto out; + } + if (__ib_device_get_by_name(name)) { ret = -EEXIST; goto out;