Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4599001pxj; Wed, 12 May 2021 08:59:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeorcSGbrfBoToLZFaBDCqgR32bXn+CJDy617IyqqWKxQ/93kEGTnn+8lJTCYehU3Ec4e7 X-Received: by 2002:a05:6402:31b1:: with SMTP id dj17mr43953561edb.7.1620835194499; Wed, 12 May 2021 08:59:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620835194; cv=none; d=google.com; s=arc-20160816; b=wsA2NfC/ezavtnRihMqOdSvrhDW0Qoou6wO0FCOiZbg8Itp7CPqkmkBqEPYraRJeU+ Sv3/nzfKopjtiuwuC4iZ9y/RmW4VgVhFRPCxFnSK2jbJBXR3OreFBfHXncjrJKEjK2V0 FKL+VyP7EIrFeN4aGXB27Zml3xjHDZvGXdK8Ln9ZeK0L3lsyqZgfR1iI6nIf1ERAU4xi IAKv1Vol51oIIrf4qipDzcZmMePbFfmDEcqPCObESZgR0T1g0bYrVTWrEmiSRRao0CXp f+fHFuYwwmoq1paAp+WgPqdhXvptaDgY73jKmhC+mvLQ72x5jcM6ksBp/NkKCwY6a78V AQag== 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:subject:cc:to :from:dkim-signature; bh=Oh5eRVUFCiHzRykUVLfPY9Wrkh8H8X3o8NOk/30gNnQ=; b=i03EX8T8oRHoA8gjaDH1fypFK3/vCsXa/irols12jfqBMNyBbnk1RZrI/VAgp9Kd/a 1ajJ0Ru9XAAj8IEZfiK+4zdCCgoyeu5+vSdYiZ7mAnGu5gbMLBL2VPRcMnYQe5V06iEk vceIc5+RY0ur0BUV/4pYpuNpvCBB/CeBdDmRe6mVwLUJOkRpyVEDf5CZb15FY6RB9ckh qrPqvFPYweb1kyfNsnWvLJwC3CYO7MeDveDUZ8J3ZdutgbGnVPKg3yK5PZsz9e7DQf8r 1O4tsNJi/IJ6jOQekYk3OB53vh42lNFiSSkMHGLk+PcXXl06WaCIKIaoqhpCBMBeb109 Osqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ppQ9n+ZN; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gx23si309047ejb.149.2021.05.12.08.59.30; Wed, 12 May 2021 08:59:54 -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=@linuxfoundation.org header.s=korg header.b=ppQ9n+ZN; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233204AbhELP57 (ORCPT + 99 others); Wed, 12 May 2021 11:57:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:37004 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235422AbhELP1y (ORCPT ); Wed, 12 May 2021 11:27:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EFFD361970; Wed, 12 May 2021 15:12:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832371; bh=G8wRUxQX+FqkXUGgG6LpGLaWdrdcdp0cRZRImkqcso8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ppQ9n+ZNFwdGcc57qTT/gnuAeF0bveYRiCKRB/3ciohWpJK09YesvnuYQC/pfLx3i 2o2NPiZQY7OcmHUwQinRNtVQrDh4WMaclj5VH1NpPFVIU5Hrs6awgN7R/a6VJAgqtQ nhHrEO08N+rjg2L5s1LXzOoMtkq/F9OkG76pWyHM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Sasha Levin Subject: [PATCH 5.10 251/530] node: fix device cleanups in error handling code Date: Wed, 12 May 2021 16:46:01 +0200 Message-Id: <20210512144828.085819896@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ Upstream commit 4ce535ec0084f0d712317cb99d383cad3288e713 ] We can't use kfree() to free device managed resources so the kfree(dev) is against the rules. It's easier to write this code if we open code the device_register() as a device_initialize() and device_add(). That way if dev_set_name() set name fails we can call put_device() and it will clean up correctly. Fixes: acc02a109b04 ("node: Add memory-side caching attributes") Signed-off-by: Dan Carpenter Link: https://lore.kernel.org/r/YHA0JUra+F64+NpB@mwanda Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/base/node.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/drivers/base/node.c b/drivers/base/node.c index 6ffa470e2984..21965de8538b 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -268,21 +268,20 @@ static void node_init_cache_dev(struct node *node) if (!dev) return; + device_initialize(dev); dev->parent = &node->dev; dev->release = node_cache_release; if (dev_set_name(dev, "memory_side_cache")) - goto free_dev; + goto put_device; - if (device_register(dev)) - goto free_name; + if (device_add(dev)) + goto put_device; pm_runtime_no_callbacks(dev); node->cache_dev = dev; return; -free_name: - kfree_const(dev->kobj.name); -free_dev: - kfree(dev); +put_device: + put_device(dev); } /** @@ -319,25 +318,24 @@ void node_add_cache(unsigned int nid, struct node_cache_attrs *cache_attrs) return; dev = &info->dev; + device_initialize(dev); dev->parent = node->cache_dev; dev->release = node_cacheinfo_release; dev->groups = cache_groups; if (dev_set_name(dev, "index%d", cache_attrs->level)) - goto free_cache; + goto put_device; info->cache_attrs = *cache_attrs; - if (device_register(dev)) { + if (device_add(dev)) { dev_warn(&node->dev, "failed to add cache level:%d\n", cache_attrs->level); - goto free_name; + goto put_device; } pm_runtime_no_callbacks(dev); list_add_tail(&info->node, &node->cache_attrs); return; -free_name: - kfree_const(dev->kobj.name); -free_cache: - kfree(info); +put_device: + put_device(dev); } static void node_remove_caches(struct node *node) -- 2.30.2