Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp43950pxf; Wed, 24 Mar 2021 20:25:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIMEiXwG0iFwudqNkvsA96h8LLrDtJLQ8u2Pg4H0n2Lgl0kDn8uaTZqgLTVEUKJ2pg9du9 X-Received: by 2002:a17:906:d790:: with SMTP id pj16mr6920447ejb.255.1616642735380; Wed, 24 Mar 2021 20:25:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616642735; cv=none; d=google.com; s=arc-20160816; b=RGcJXZkZHvfKsaeMb0ychFddR4Eq6NesOa6eGRR3jo9EBPaue3BT5XYUGs4vQPi1ck ZI9N/VQ6m1r60FWOpGL/eramdo/3V7ZY6o4KBfgifOQDALBd9EreZkHW53dDO3w2T7q/ dQm6Z1/6CU8ZKJRK3xuvrslB+yhyJ2CqQGHG12EQ9nvdL5Rgz5wct10JxsRahip0ZpA2 FeRQ302kQpIxSEdd1fJLa+R0s/tmaiVSv1Ds0q6Bwer6BJFo1S67Z+NIA5D8BeoyeIxo HobuOt0fVA9gpT3iPwAKXf8p95pqCq7W8mAB30S3zDkpOgfre2mVuLqoGHgDluPAlk2B ca0Q== 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:cc:to:from :subject:ironport-sdr:ironport-sdr; bh=/Jmck9nWo1Ym9fLxG1vKeE0jHi8o/tH4EO11xzd10yA=; b=DF4d637lQrUPEonjP7r32n5xMsOPMCW+EMZ9XVKHGBTL+sLIye0sRGgcSEYqyDSkaw 5bG2V18f35AJpHzII9Bn90LNTNnLowpWaNxVyHZriSsJT1D/QkB8pMqMUw3eA4YF26lX RY0r7FLbQSJhT0KZW6WRAXC3173MFuJuUoqswMy8UqyLv1fPsmV/OH05OS2ElIRCANml zCsKzmv6YIG6oVZ09ZqIYVe7eAKBjDSwhoiiFmlsWR7W5UmGFSJ81PlSkMjiL/QKVi9x mBi7nPPQOf2GIxMJlNcXSAfOmOTjY8PT0ZQ7mcNwffQyC5mJ0e2IrUK8dfnP8+uV3Du/ 2KYQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r22si3069238eds.172.2021.03.24.20.25.13; Wed, 24 Mar 2021 20:25:35 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238300AbhCXVCO (ORCPT + 99 others); Wed, 24 Mar 2021 17:02:14 -0400 Received: from mga05.intel.com ([192.55.52.43]:37982 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238227AbhCXVCC (ORCPT ); Wed, 24 Mar 2021 17:02:02 -0400 IronPort-SDR: yTZEL2TQFsJy0ot+bji1yE8u/GSdhdBxvHvP0aT4mwD0cM5E1dzCGZ1zxeMfuuTjcPGQIQoYPz 9XlFrOoK4H9Q== X-IronPort-AV: E=McAfee;i="6000,8403,9933"; a="275911380" X-IronPort-AV: E=Sophos;i="5.81,275,1610438400"; d="scan'208";a="275911380" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2021 14:02:02 -0700 IronPort-SDR: kfYrElActq2cIErox7P7fpRMpkbZxrWpXugfzR+FNjRc4BK7BSfgySaWqbO+iXzfW/StzvjjEe t9Mm+06nRHYA== X-IronPort-AV: E=Sophos;i="5.81,275,1610438400"; d="scan'208";a="442415541" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.25]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2021 14:02:02 -0700 Subject: [PATCH 3/4] cxl/mem: Do not rely on device_add() side effects for dev_set_name() failures From: Dan Williams To: linux-cxl@vger.kernel.org Cc: Jason Gunthorpe , ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, linux-kernel@vger.kernel.org Date: Wed, 24 Mar 2021 14:02:01 -0700 Message-ID: <161661972173.1721612.9458160848430375459.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <161661970558.1721612.10441826898835759137.stgit@dwillia2-desk3.amr.corp.intel.com> References: <161661970558.1721612.10441826898835759137.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While device_add() will happen to catch dev_set_name() failures it is a broken pattern to follow given that the core may try to fall back to a different name. Add explicit checking for dev_set_name() failures to be cleaned up by put_device(). Skip cdev_device_add() and proceed directly to put_device() if the name set failure. Fixes: b39cb1052a5c ("cxl/mem: Register CXL memX devices") Reported-by: Jason Gunthorpe Signed-off-by: Dan Williams --- drivers/cxl/mem.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c index e53d573ae4ab..d615f183520c 100644 --- a/drivers/cxl/mem.c +++ b/drivers/cxl/mem.c @@ -1204,12 +1204,14 @@ static int cxl_mem_add_memdev(struct cxl_mem *cxlm) dev->bus = &cxl_bus_type; dev->devt = MKDEV(cxl_mem_major, cxlmd->id); dev->type = &cxl_memdev_type; - dev_set_name(dev, "mem%d", cxlmd->id); cdev = &cxlmd->cdev; cdev_init(cdev, &cxl_memdev_fops); - rc = cdev_device_add(cdev, dev); + rc = dev_set_name(dev, "mem%d", cxlmd->id); + if (rc == 0) + rc = cdev_device_add(cdev, dev); + if (rc) { percpu_ref_kill(&cxlmd->ops_active); put_device(dev);