From patchwork Fri Nov 22 13:42:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 13883192 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B431F19BBA for ; Fri, 22 Nov 2024 13:42:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732282937; cv=none; b=E+IgbSMQpOKxpxueZj0tro0TiJ4Y4NtNYdlw7VyzTR5CAG/JVWQPyVAAAHuaVf5N49mMurjk7OCiyuW0Sw6uK88IjeJX5Z+CUdCkaNN6kiMhBZ/9cYYJK05A1b8yag79RwPf+jRJt+Z411hfgjQiurFq+zF29wpWkUQ8YAPgH0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732282937; c=relaxed/simple; bh=7rpxTCbAovNOOaSE5QqV66Aj2XvYh1HPcKPEvedvnPM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cIWnxLRUtzJPJDtMKkNeHUtPCnmURn1l3aIf4wTUtLOiv9GlLy01aWB3VS7+aGzucOFLDVQFOcrHSKb9dkMt7d5tz/7Ptk+OgYpH+kDjh9rlWv6Jji3y1hbBjHUI/fobg7fbwZxqUGS9lYzJmQQQA83DEy/CM7Mirskom7JAsPU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=sEL4n2zv; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="sEL4n2zv" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-53d9ff92edaso2468965e87.1 for ; Fri, 22 Nov 2024 05:42:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1732282933; x=1732887733; darn=vger.kernel.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=hR6Bt9wGJi7TnVA8wmi9rRKI8kqmYyf5TPLbM4hQqZU=; b=sEL4n2zvxEzzGCp/hRVpZ7udi7krOdjTeN96A96SYVR7j0zgpdrRjPxJH44Jj41hYk /S6CMByFPaf6M15/0fDC2ECv4jZGpEODQ4bnyALeLP+eNng5eVm6K7wGAVVOqMA497+u rtop/DjDkb9Nn9Pf3NkrHLEi+nQxBhBfRn4MlIndhGmjvLUD1t6h+Y20jvN7j6N1NdeK qdwj2G/vDjQZVGTwsykzT2EKUZtvSsKM4sPng4zgczZd6qtwsfOFWbwcW5EuCpEjS0+l aKmV1smSPRsYroSH63aKdSgujnvn9Ad+RQH0bdU/74bfJgGPWc5cnym4O1XtKaPJduP0 sqiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732282933; x=1732887733; 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=hR6Bt9wGJi7TnVA8wmi9rRKI8kqmYyf5TPLbM4hQqZU=; b=amQqcjA+7AW0/j+bkdQOckQ6rGyKAmwX3n7P5odHvJop7UnwlfZmFL0hw+W+WgG2Nj 47jKsvleITR14fILQx01s4mO2EhiT0FXhQN+4Rud3ZAmyLoZ1qN4pCxQsIoqDGdCBl57 UfW5Nz8Ixwi+RgiHLZhtwFDvVTOlumqMPdpGw/tKgmoHCbT2KmikkIxj+DTnvfEhPag2 v9s8Tom1It3R5AEK6k4NrgYDEon/aWiJP4QLDN01kzOmFGhuX7HJ+azjUQWO7piej6Jn YsUVTUbhQvLMnVtTEa6vml3UZ8/vbtUmxbJ57+giZWKJJhibcB/uQerjFwvKT3Zbrg8U 90DQ== X-Forwarded-Encrypted: i=1; AJvYcCWfoMj0LGdNAS6hXEDzX38VxwjYDV/dAg5/pQudwtSJK2O55QkPeneo0h10PfuPT2/MObkmQRUdGA==@vger.kernel.org X-Gm-Message-State: AOJu0YzQO9YICzA1+ylFZqvOIlAprZBHFdbCbEqjLpopJqjgu84XCYHN JWbF8n6JcsjwqOVtmvt7Zry0irQDA+bIoyR7sjiZrLOi4xkt+8f6hp/rQhf+gtM= X-Gm-Gg: ASbGncspLyqS75L5qvfwkMr6WMZhdlLktZRKBhCbc+xTH+4HnVgwSZIpF7pGCfJR/jW pI5MymUdcerVf/hV0W7VEcTljrFKUjSwwAt+htpRcjYiQ6HBWv7E1mRfhoZegpM7KxO4gBSEpr6 O9TZfmrPAbMDs4IacAoF3+nWaGDcmyBgUiweR9siJrt5+EoJGyczvduBkR08zMyC7ewMk75Oz0P 9CLdJIiomg0deS5mNLM2JOEphVVNbSx6A5h3pDFMdiIhfBRVhSo0FijjkLPuEtnXTnOW2wkLrOw fODmu5ejAfOQ2ti+vzgLpVfQ X-Google-Smtp-Source: AGHT+IHyw3GH8RrHFNfGtL+1PQD/slLLct9YZQoWaph6bHJlpew+jBHD6XIcc07hIt3G/uvpFcVtsw== X-Received: by 2002:ac2:4f11:0:b0:539:e1c6:9d7f with SMTP id 2adb3069b0e04-53dd389d698mr1582840e87.25.1732282932796; Fri, 22 Nov 2024 05:42:12 -0800 (PST) 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-53dd2481e73sm376432e87.120.2024.11.22.05.42.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2024 05:42:12 -0800 (PST) From: Ulf Hansson To: Ulf Hansson , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Sibi Sankar , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 1/2] pmdomain: core: Add missing put_device() Date: Fri, 22 Nov 2024 14:42:02 +0100 Message-ID: <20241122134207.157283-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241122134207.157283-1-ulf.hansson@linaro.org> References: <20241122134207.157283-1-ulf.hansson@linaro.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When removing a genpd we don't clean up the genpd->dev correctly. Let's add the missing put_device() in genpd_free_data() to fix this. Fixes: 401ea1572de9 ("PM / Domain: Add struct device to genpd") Cc: stable@vger.kernel.org Signed-off-by: Ulf Hansson --- drivers/pmdomain/core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c index a6c8b85dd024..4d8b0d18bb4a 100644 --- a/drivers/pmdomain/core.c +++ b/drivers/pmdomain/core.c @@ -2183,6 +2183,7 @@ static int genpd_alloc_data(struct generic_pm_domain *genpd) static void genpd_free_data(struct generic_pm_domain *genpd) { + put_device(&genpd->dev); if (genpd_is_cpu_domain(genpd)) free_cpumask_var(genpd->cpus); if (genpd->free_states) From patchwork Fri Nov 22 13:42:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 13883193 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B39292AF04 for ; Fri, 22 Nov 2024 13:42:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732282939; cv=none; b=o07uyQoEmtf1Xw5jT6JUS1CyDC85HbV4BONzxUNwtm5VqwaHQOm8Fd6UP1zL5WyppgteqP7RiLNkaJtcYDHe1Yjc3iPUPxaOYD2ThFYYC/ddrrbLq2WHPP7JdHYrLQP4tqgy6f3yS62wkI07j+1MaRhoHWnIpmn8hpN+nDPEtkE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732282939; c=relaxed/simple; bh=zkH6RmyvNVFvMmhT+5A7e3uFPfJEHUmdMgV1uxwJ3Kc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GcuSO0OR3lRWoN+56xD8OLUYxlqyJFdtYEkgVZc8pnKFfJFC874DLOSKw/VvgOveDQnaiAOiK2w8qvmOlhEmR1qUCQqjw9LCYX4qgVxfgvNTHVRjoLnWLcJfE7ITAhEkex1BDYB+/9ixMhvC7seJMb+R4VR7SrLAicYG9l1vuhQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=OMoMBqC0; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="OMoMBqC0" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-53dd9e853ccso184546e87.1 for ; Fri, 22 Nov 2024 05:42:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1732282935; x=1732887735; darn=vger.kernel.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=4difOWFZgJjnD1C8UcBJOhNA8o5YsQWO3tN/+p0Mf1o=; b=OMoMBqC0dpOi6jQJ6PGGIiAvX1RFa3ltfKUDsGZDA0xythBQNop2afL8vtWrR8lOvR QCH6AfV12eG6shT+6Lx/nlDQYgva6+SmsEVjFnl9zihdjVKnzr4MM8KvPhnI/YknmKee zVH64f2V+SFyN2ovbC2a1U4sG0MELNRqfAfbGCFD8WEeoFX7W+1ZM8nLuTQrkIHAuUyq HKjMwCoKYUx+dTBgZCSeqG67yS8Qmrn6SxjCtnrzDMoar9IQWMXvE8KgQcgKJTubzWln Mwa1GQMBSNoXxbLY8qQ6fBPE6s51CocWbZqSIEZpS9ma9WjW28CXRJM0vRGa72PH7vdb y/uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732282935; x=1732887735; 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=4difOWFZgJjnD1C8UcBJOhNA8o5YsQWO3tN/+p0Mf1o=; b=uoJbhX1CAn5eNaNvCyx35GkT4fdBKt+N1pYswSr5Er1xB5zi1I/lgOj/YLzBOWgmJu gVvFZftHoLKY1Auz6m7xb452vK6XfRP7W1vI+WMgpd15irGGZNO5PdRrLlHgte6wNN1l RX36H03CKqzrSXg2iQdTbjEI0yyJNZkex4s5nE+2tKJyYhTt7DD8dinIVphQAAMPRYSb HHQ+KBYCHQ8ni6KVUyphtmL3/oXrO2nHdlpIRpVjeA+xAFhW5TvgBlaznBY14XR4+eNP cNQj6Ltl4DBFPowo7vR+o6oeO9lDd/5R1BotYnCyO9DvcBL2hn4GMBKn75LZS/s1IAfO njrQ== X-Forwarded-Encrypted: i=1; AJvYcCXsrqz05lwaRr++rNmaxq7VTXOG4qNCLhaV0VDzf5NKXISPPE+xw9Yf8bTozpXWqNl9qdX6TEMImg==@vger.kernel.org X-Gm-Message-State: AOJu0YxxmoyELlI0hPQxsrxm+Va+ktn/Krmdb2rR/VL2NmEwoyJmpE59 yF4GCUJCFKf0+5vV6iUBC+MXkNKmS4Tdl8W0USj48IEwBAqXfTwQeWHvRiw8rGg= X-Gm-Gg: ASbGncvj1+vvBGQ11bQuA/eFsV2KxyWhF0n8UhM4q+R32YFPXco5rUKPPd3C8AqLFWx ujZ59+bIvw0I0xti/3gXqj5cpI6pa71h17RGgohKMnYT/xCAkQeXN7ruB9aMYY0yvcOTt4QYmSv bjiv6gGgBeJ1MY35PHdYvLXEbASCV2AfsMzYGMCC1JfgMYACjErQoECZv215qvArTQxYDmPCS6D +tAwyIyaW+0rsx4GvNRw5pLSBgBc8DCjMDRkh3XsaHe9Jx4BniMZV7+2eK6qxTh6e37NvFHWgMn WaCEaYZo7SfkD18VQEvDwXnP X-Google-Smtp-Source: AGHT+IFpXYUD+s/zi1m8hUlKbDnxnNx0uM97l+zyDIOWiFoCB6hbeMWDPChCxVJnNPG7XSOTrGoKsg== X-Received: by 2002:a05:6512:3084:b0:53d:b998:b7e1 with SMTP id 2adb3069b0e04-53dd35a47ffmr1986425e87.3.1732282934904; Fri, 22 Nov 2024 05:42:14 -0800 (PST) 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-53dd2481e73sm376432e87.120.2024.11.22.05.42.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2024 05:42:13 -0800 (PST) From: Ulf Hansson To: Ulf Hansson , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Sibi Sankar , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] pmdomain: core: Fix error path in pm_genpd_init() when ida alloc fails Date: Fri, 22 Nov 2024 14:42:03 +0100 Message-ID: <20241122134207.157283-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241122134207.157283-1-ulf.hansson@linaro.org> References: <20241122134207.157283-1-ulf.hansson@linaro.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When the ida allocation fails we need to free up the previously allocated memory before returning the error code. Let's fix this and while at it, let's also move the ida allocation to genpd_alloc_data() and the freeing to genpd_free_data(), as it better belongs there. Fixes: 899f44531fe6 ("pmdomain: core: Add GENPD_FLAG_DEV_NAME_FW flag") Signed-off-by: Ulf Hansson --- drivers/pmdomain/core.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c index 4d8b0d18bb4a..bb11f467dc78 100644 --- a/drivers/pmdomain/core.c +++ b/drivers/pmdomain/core.c @@ -2172,8 +2172,24 @@ static int genpd_alloc_data(struct generic_pm_domain *genpd) } genpd->gd = gd; - return 0; + device_initialize(&genpd->dev); + + if (!genpd_is_dev_name_fw(genpd)) { + dev_set_name(&genpd->dev, "%s", genpd->name); + } else { + ret = ida_alloc(&genpd_ida, GFP_KERNEL); + if (ret < 0) + goto put; + genpd->device_id = ret; + dev_set_name(&genpd->dev, "%s_%u", genpd->name, genpd->device_id); + } + + return 0; +put: + put_device(&genpd->dev); + if (genpd->free_states == genpd_free_default_power_state) + kfree(genpd->states); free: if (genpd_is_cpu_domain(genpd)) free_cpumask_var(genpd->cpus); @@ -2184,6 +2200,8 @@ static int genpd_alloc_data(struct generic_pm_domain *genpd) static void genpd_free_data(struct generic_pm_domain *genpd) { put_device(&genpd->dev); + if (genpd->device_id != -ENXIO) + ida_free(&genpd_ida, genpd->device_id); if (genpd_is_cpu_domain(genpd)) free_cpumask_var(genpd->cpus); if (genpd->free_states) @@ -2272,20 +2290,6 @@ int pm_genpd_init(struct generic_pm_domain *genpd, if (ret) return ret; - device_initialize(&genpd->dev); - - if (!genpd_is_dev_name_fw(genpd)) { - dev_set_name(&genpd->dev, "%s", genpd->name); - } else { - ret = ida_alloc(&genpd_ida, GFP_KERNEL); - if (ret < 0) { - put_device(&genpd->dev); - return ret; - } - genpd->device_id = ret; - dev_set_name(&genpd->dev, "%s_%u", genpd->name, genpd->device_id); - } - mutex_lock(&gpd_list_lock); list_add(&genpd->gpd_list_node, &gpd_list); mutex_unlock(&gpd_list_lock); @@ -2326,8 +2330,6 @@ static int genpd_remove(struct generic_pm_domain *genpd) genpd_unlock(genpd); genpd_debug_remove(genpd); cancel_work_sync(&genpd->power_off_work); - if (genpd->device_id != -ENXIO) - ida_free(&genpd_ida, genpd->device_id); genpd_free_data(genpd); pr_debug("%s: removed %s\n", __func__, dev_name(&genpd->dev));