From patchwork Wed Oct 2 12:22:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 13819755 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ED8C9CF31B4 for ; Wed, 2 Oct 2024 12:26:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=GnPQMJcE35HfZ9AP9Q+AP3/u7Io2rZuoy0lFJRDyvTQ=; b=SJI78b9x8HVVbJvV9Q79mQPKhk Fd45q+Ub+V83Qg1wy99J8UlJusAHEG8yiKF+xOxtlHBlWrU8OPhzMRIfvZX6pqR/HBrradACCP5q7 BOgwvDb91kKjM97NCvNVLRZsTcHcTiNA+gjqCsSwc+Ow333xzyPMrbYQ6ClWrUqrAHl7/gUmEmcpK MprnJXG2cGUrB69nTY874ygI4OtSu933wM4bOlhu3f0Ur6n5/fqjpliJGQtn1hKSbOk/0WdD5FsHi zxxGUW9OR4h5bXyazZrsaq8hjlogMf8zGtxig6ACAQ/lAgwlnHBfAJT1TH4W2DPtQaWOOqnqkvg7I EeVlyA2Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1svyR7-00000005rsr-3Xr1; Wed, 02 Oct 2024 12:26:33 +0000 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1svyNR-00000005qUk-26GM for linux-arm-kernel@lists.infradead.org; Wed, 02 Oct 2024 12:22:46 +0000 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-5398b2f43b9so707863e87.1 for ; Wed, 02 Oct 2024 05:22:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1727871764; x=1728476564; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GnPQMJcE35HfZ9AP9Q+AP3/u7Io2rZuoy0lFJRDyvTQ=; b=ZHfgKQAz3dGzsvo8EjVELwE/lksnnfU37QwVZDziduvY+woDE1lwaoyYMxFbSxOdAb j4FP9ybnQ1T3Ch0YGxINSSyr4rg9kOYkOW4fMMeTm8cPyhaVusPHicJ1jnsdZqQFiVK9 5lsjiUbhRbkF4fwse12zDMYpVzUlsQpoeLdp5pSkYDipd+qYxZ/v5phQa3egOhrUJEcs L5oFhtL7ivw/FJURM7XJjAof076dXXgATc1gUn7Ow+32KUTVBkwBGKuqBEEmOdIlYcsq u0BXkUPwNW69cqJe7SHPoGGhxk+TgQcnAMldq4x/rY5e4erTtWLl8N0lyGrSOsTa1jmb dqzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727871764; x=1728476564; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GnPQMJcE35HfZ9AP9Q+AP3/u7Io2rZuoy0lFJRDyvTQ=; b=X+TjBg5j86cr4p0NdrUijUgbU3bPTUpr73EKv5ZBxvHdSltvNBiaXZU9wNkI5Rewcn Sz8uSAjkdhRkiw++4nwFtjbr5q5/tGS7ChbMv7HHYdvENz3jzAg8XIohWrRlvxg98qrH 6U5pM3KIa1wKAMtcaX59Uw2XvydV77E0/mz7Y4tlzj4kaqnmzCSV/D9mN6Sqej/U6qRW /bJiOuos5FS+6MLNsoUCr1Nq8+5jQszJS9L29vSWY6Yq9jzcKlXPJzG43W4XFGEuW1DT dPEkmwSsoYK/QHUhpAMXoLY7chgfcPu6fnvJzW6wtvqvBc6W0hYQgmasJZAWx2eCQSWN HnRg== X-Forwarded-Encrypted: i=1; AJvYcCVMy8r0eN9Jbm8btAgAgrfMw9ObQFMFbGPplxXROlA1c6FldzPO/O3sS/OlHuC02p17RdKoIV1K8Y+68erDay4/@lists.infradead.org X-Gm-Message-State: AOJu0YxavF8R0v2e0gWHPWGbebmkaZxXFfl6ZlHUWXPMEvl/zsJlTJvj bUquF5ZExnVVvsQwAOVx2crymX8vfH585cRA54z6eaC3jvhKFBzdjI4E38vd9fQ= X-Google-Smtp-Source: AGHT+IH3lbHH/Ci/Lm2nPio+9vcLRk9yL/BoeI12+KlsgJmqos4Z7kBLLfAx4B214LknbA9lF9GWVw== X-Received: by 2002:a05:6512:239c:b0:538:9d49:f740 with SMTP id 2adb3069b0e04-539a014dd0dmr1050179e87.15.1727871763458; Wed, 02 Oct 2024 05:22:43 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-538a043204fsm1912659e87.165.2024.10.02.05.22.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2024 05:22:42 -0700 (PDT) From: Ulf Hansson To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: "Rafael J . Wysocki" , Dikshita Agarwal , Vedang Nagar , Bjorn Andersson , Konrad Dybcio , Nikunj Kela , Bryan O'Donoghue , Thierry Reding , Mikko Perttunen , Jonathan Hunter , Stephan Gerhold , Ilia Lin , Stanimir Varbanov , Vikash Garodia , Ulf Hansson , linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v4 02/11] PM: domains: Fix alloc/free in dev_pm_domain_attach|detach_list() Date: Wed, 2 Oct 2024 14:22:23 +0200 Message-Id: <20241002122232.194245-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241002122232.194245-1-ulf.hansson@linaro.org> References: <20241002122232.194245-1-ulf.hansson@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241002_052245_559761_2B1756C1 X-CRM114-Status: GOOD ( 13.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The dev_pm_domain_attach|detach_list() functions are not resource managed, hence they should not use devm_* helpers to manage allocation/freeing of data. Let's fix this by converting to the traditional alloc/free functions. Fixes: 161e16a5e50a ("PM: domains: Add helper functions to attach/detach multiple PM domains") Cc: stable@vger.kernel.org Signed-off-by: Ulf Hansson --- Changes in v4: - New patch. --- drivers/base/power/common.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c index 8c34ae1cd8d5..cca2fd0a1aed 100644 --- a/drivers/base/power/common.c +++ b/drivers/base/power/common.c @@ -195,6 +195,7 @@ int dev_pm_domain_attach_list(struct device *dev, struct device *pd_dev = NULL; int ret, i, num_pds = 0; bool by_id = true; + size_t size; u32 pd_flags = data ? data->pd_flags : 0; u32 link_flags = pd_flags & PD_FLAG_NO_DEV_LINK ? 0 : DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME; @@ -217,19 +218,17 @@ int dev_pm_domain_attach_list(struct device *dev, if (num_pds <= 0) return 0; - pds = devm_kzalloc(dev, sizeof(*pds), GFP_KERNEL); + pds = kzalloc(sizeof(*pds), GFP_KERNEL); if (!pds) return -ENOMEM; - pds->pd_devs = devm_kcalloc(dev, num_pds, sizeof(*pds->pd_devs), - GFP_KERNEL); - if (!pds->pd_devs) - return -ENOMEM; - - pds->pd_links = devm_kcalloc(dev, num_pds, sizeof(*pds->pd_links), - GFP_KERNEL); - if (!pds->pd_links) - return -ENOMEM; + size = sizeof(*pds->pd_devs) + sizeof(*pds->pd_links); + pds->pd_devs = kcalloc(num_pds, size, GFP_KERNEL); + if (!pds->pd_devs) { + ret = -ENOMEM; + goto free_pds; + } + pds->pd_links = (void *)(pds->pd_devs + num_pds); if (link_flags && pd_flags & PD_FLAG_DEV_LINK_ON) link_flags |= DL_FLAG_RPM_ACTIVE; @@ -272,6 +271,9 @@ int dev_pm_domain_attach_list(struct device *dev, device_link_del(pds->pd_links[i]); dev_pm_domain_detach(pds->pd_devs[i], true); } + kfree(pds->pd_devs); +free_pds: + kfree(pds); return ret; } EXPORT_SYMBOL_GPL(dev_pm_domain_attach_list); @@ -363,6 +365,9 @@ void dev_pm_domain_detach_list(struct dev_pm_domain_list *list) device_link_del(list->pd_links[i]); dev_pm_domain_detach(list->pd_devs[i], true); } + + kfree(list->pd_devs); + kfree(list); } EXPORT_SYMBOL_GPL(dev_pm_domain_detach_list);