Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp520560pxf; Wed, 31 Mar 2021 09:06:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZvKqrfwCJ1zICmsoiltcNRieXvX2C07gZiRVf8tsKaaHg99NNnUU9KQwlbnSK6AsTUsmk X-Received: by 2002:aa7:c88e:: with SMTP id p14mr4515838eds.119.1617206787505; Wed, 31 Mar 2021 09:06:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617206787; cv=none; d=google.com; s=arc-20160816; b=rbMxf3a6pys/w/ikVZF5vhmVR/JLrlQyy10uqCc3b0WkS0cr0B8F/2fq6qE1PE84eM FdDNiD/hy94X4YwRFKDwsQhojBghJDD5BXMLT39pj+skA3WpUMvjUtD9QOE8YM7UC7qQ ovXJadLCF/9ShJew7+X3OsM4tB2+xAiCta9Ce3ZKegBQMzxNU1kfx31N5mH/M0wG8P0i Vxqq0RRlRJkK/LcATQ9SzycWLpx5hGZSh+qNdD2y8MZjXviRvw4r4zJVTFn2dhwAogGi DZpf1cFm3v/zDQGkkGvuuYL/OEv0Awtaqz2c0NynGzI8as4O5xCpodRLlUVGubweT7Bk X8nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=/K8jhwDcWdtQO8TgpjZZoFEiAtw8FI9cBvy1a1rTDN8=; b=g94AVOd04eCWg4O3reP6h1s5++xuPehA+zZMxGzkNYZe8jDzyIwcsqQK7kcNkhR8a8 vbWJyDyYDdnrDZHl4SGs66WsPKE7Xf2oMLMcp/rw2Y4z/O5XkNY3pAvr7iDHaYfISNii tUMVz0bE1hLdHIKuhVU9G67RVfDTnwMEKx+/PAk7WUIVKG8zZFCbl77MDDz5hLFtGQx8 x9QAIckPn9RH6WHM4HgNqbNAypxrASVbB17L2LhVLXwJ0cCh86s+GPS7wxX37pOosXJA 7Z1LSn8xyxgqXiqMsssMVRvo9iGD/xgfDM+DRQzX1h/sNIE4nBktq0Y8+dNB02lckTwY QdBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=n98YQxI+; 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 d16si2253188edc.45.2021.03.31.09.06.04; Wed, 31 Mar 2021 09:06:27 -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; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=n98YQxI+; 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 S232301AbhCaQFD (ORCPT + 99 others); Wed, 31 Mar 2021 12:05:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232319AbhCaQEo (ORCPT ); Wed, 31 Mar 2021 12:04:44 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8303AC061574 for ; Wed, 31 Mar 2021 09:04:43 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id w3so30896219ejc.4 for ; Wed, 31 Mar 2021 09:04:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/K8jhwDcWdtQO8TgpjZZoFEiAtw8FI9cBvy1a1rTDN8=; b=n98YQxI+8gd6h3kZzKYrEF739lerNLf9t8oyCoS2TJyNMaNFL6UJhBu/UuusrT4qiF 4IiTkSg4USBePHxB+IYW/b9H74TqaoiTSLaPyMsY58DnwNmx1m2p2nInVBop5vaFoFqF 1gTDhuJ2bUKv3YWP0erWmiFTAGXG7WuKr01VIR8J6Mn3aR9e3BW4qHcpjTLr/2rJ1hOy /SaZ0obFL7QqVEpsM0+l+1cNkCBrcElevYRJokNDUp0KeLWBDXbm2uBLsx7+M6U6K9Ar IJMgFpN0v9+iBI3vNt5IqaYv+CspHhLfbmjIrqkJzx+nLicb0UeJ3uECqj3eL39YZV+a 2PNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/K8jhwDcWdtQO8TgpjZZoFEiAtw8FI9cBvy1a1rTDN8=; b=gVim0m+1QoINELpLjZ9aj0UNWF5yYRRUP+caZcvVGVeRq8KvKoO/Ti9ImpTm7VYkZF FFLGAVuaGTEK15b5hhiLTFyBi+DUJvCxsJh+0cPEabPugeHFOpNOhNkjb9WYyAqeqdAX SAUKjRczjEYwd4spNW+cXqLfu2KN8IXB/dU1kI521zNv/bMxoVTt+PTCDhy0RMNeTnuy LXLXi0GHw+UVtZ1RNaZpVIR6IIus3HQHwKF1yucmPIYF3CbzZKS1MWzuIdUFDR6IU9Q8 +SjhetLU+5ZGfevldi54wVs+ZrqO6VA3fIejqGC4BXmyHbTlSodM3MRqlAGz9TTQEHKc ukLA== X-Gm-Message-State: AOAM5321JY/14YsbUt47zacaLhDW6gcMV5DafJlW5VOu8o+3h9M9TwgS gbfkrF0RWon3CdHhmAFbcQBSoI0v3DvNC9MdqYfVKA== X-Received: by 2002:a17:906:ae88:: with SMTP id md8mr4161716ejb.264.1617206681177; Wed, 31 Mar 2021 09:04:41 -0700 (PDT) MIME-Version: 1.0 References: <161714738634.2168142.10860201861152789544.stgit@dwillia2-desk3.amr.corp.intel.com> <161714740233.2168142.11116065966198937093.stgit@dwillia2-desk3.amr.corp.intel.com> <20210331130953.GG1463678@nvidia.com> In-Reply-To: <20210331130953.GG1463678@nvidia.com> From: Dan Williams Date: Wed, 31 Mar 2021 09:04:32 -0700 Message-ID: Subject: Re: [PATCH v3 3/4] cxl/mem: Do not rely on device_add() side effects for dev_set_name() failures To: Jason Gunthorpe Cc: linux-cxl@vger.kernel.org, Linux Kernel Mailing List , Vishal L Verma , "Weiny, Ira" , "Schofield, Alison" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 31, 2021 at 6:10 AM Jason Gunthorpe wrote: > > On Tue, Mar 30, 2021 at 04:36:42PM -0700, Dan Williams wrote: > > +static int cxl_mem_add_memdev(struct cxl_mem *cxlm) > > +{ > > + struct cxl_memdev *cxlmd; > > + struct device *dev; > > + struct cdev *cdev; > > + int rc; > > + > > + cxlmd = cxl_memdev_alloc(cxlm); > > + if (IS_ERR(cxlmd)) > > + return PTR_ERR(cxlmd); > > + > > + dev = &cxlmd->dev; > > + rc = dev_set_name(dev, "mem%d", cxlmd->id); > > + if (rc) > > + goto err; > > > > + cdev = &cxlmd->cdev; > > cxl_memdev_activate(cxlmd, cxlm); > > rc = cdev_device_add(cdev, dev); > > if (rc) > > - goto err_add; > > + goto err; > > It might read nicer to have the error unwind here just call cxl_memdev_unregister() Perhaps, but I don't think cdev_del() and device_del() are prepared to deal with an object that was not successfully added. > > > - return devm_add_action_or_reset(&pdev->dev, cxl_memdev_unregister, > > + return devm_add_action_or_reset(dev->parent, cxl_memdev_unregister, > > cxlmd); > > Since that is what the error unwind does at this point. Right, but at this point the code knows that cdev_del() and device_del() will receive an object in the appropriate state. > > > > > -err_add: > > +err: > > /* > > * The cdev was briefly live, shutdown any ioctl operations that > > * saw that state. > > */ > > cxl_memdev_shutdown(cxlmd); > > Then this doesn't need to be a function > > But it is OK as is Unless I'm missing something I think it's required to use only put_device() to cleanup after cdev_device_add() failure, but yes I don't like that cxl_memdev_shutdown() needs to be open coded like this. > > Reviewed-by: Jason Gunthorpe Appreciate it.