From nobody Mon Jun 8 12:11:59 2026 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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 65A7C3C0613 for ; Fri, 29 May 2026 09:59:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780048751; cv=none; b=LFGmDpTsVgHtySwPbG6jb7dyxA2wDfCplEAH/0OT5uAbmnZMUf6eN2gD3M8APD2nPdefEgO+qnXJEDvL00Ang+lV8sse/7YmqLv0o1CI94IrUFP1XmGcsQBc0l09RVqdP2/tXvNLi9tmyWQVbbXixl2id5cuOoyCV2p6rlULt74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780048751; c=relaxed/simple; bh=zpk7WwA/HuQxQBjY/4PQ71+fGV/wQyHGZ3pc6imOA00=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=WvtvGT0Lt78voCrm8I145kNPjvzcaIHTEH5dgjgbZoYvflaYd9c6nEtCmtoMjpq+k+2bLe3pdZnyA77DW08HlNKUH8tGBbhcrIXh9uCw4J+L2r5+za8PCoDa89Smpt/nBwx0qiDgR8do+72DOem9QBTKfenAkMTpYeMkPzUaypE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=isjNXlU/; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="isjNXlU/" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-5a875ca312eso1425739e87.3 for ; Fri, 29 May 2026 02:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780048745; x=1780653545; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=foAANAeJfAfM/cw3YT3GPXeC07g5W781y+R6Ho2ugfc=; b=isjNXlU/TGPSgdI04B4Or74xg0Vbh8bhXZlWVHdpqiEMvZBwQurDkURgFIKvS8kK0v XmN6k/C6FErpbOmEizFgKAQd8bOXGr08bsRDW0UYhKi0LNMRpjbD9CuW2ovSJfaCLDR5 k80hRIZRxHwFOu87wVmd2ekQBFrHzu3I+Uw2ZVGub6A4ZQne0/Ycqc+6gtJLyFAijlr+ fa5H5mFxk8BGOwFHNxIxYY7cRSDC1VLTm9rtGbQTGfHgUQoqfjWTIrcmRDq0SI8Gac5u 8e6oNyjlIl9eHyb/by0bCRjkkJrq2VB4tl15Fuq/GH25XPJjkypkXmwa06k2mQ8Ry5Ah wmTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780048745; x=1780653545; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=foAANAeJfAfM/cw3YT3GPXeC07g5W781y+R6Ho2ugfc=; b=h38TwgLH0yv9OM3AXcEIbROYRwFzSZ/bl0H+nMWMZkytDfJQh0euyqqO58yRJHGpN2 +81AJEGcdi8emAlBjiCh0w8rTMo9G2aM2/zNi24UX9mHSHgvj5QElzjeRB8N9iRE//C5 2px0Np2LOQ9ZdAPF4krSY0HNSnyIbokm57z5g0vVcfzqF1bGhXC4Zwwzq9EvdUT+SrPF zvY9mgmOJ4lNefRa49iFhYZc/iVygJzIbqWhfHlIXsnjDin0SZ6LHO9COP25VZLlW9/L 6uocMoDqrcFynCEFTMRhLbUIl+i2PY26gY5cpaoQIn7BkZxe695Ixn/m6JQwyJDvx1QO U0aQ== X-Forwarded-Encrypted: i=1; AFNElJ9CmWpsv7SGHWs/uA7Su9IHeBQ5HyUM0ZeE6n/tn5gjZB8HJW8DQxtT6GH0y3HJCuZaxhtJMcRy4O/5XDo=@vger.kernel.org X-Gm-Message-State: AOJu0YxK6crYG54KBY1sQxxy481neGVcYwFXiq5SAZvTYL3Ejk68BdP3 42qbO+jUdGNcXKPEGCXa+o5y3XRcfiSx8Ge6RJ77t/0SUTqjrjB7DFly X-Gm-Gg: Acq92OEzgD3KjzzUPTAVeeZqrvsMLK831Vf/lE6XyyPQ8dO3M5UUz/wkDQ2X3FsVvRh LqgS1kEYDYdaK1O77ivrB4fz53YjIqiygMWCSnKrpEqTyJ2eL8/fzBUYh4ekGNBhLAC0YG+pzYb 9zg7sE2fVIZ4CQNztd95OP6NqaOMmDrrXNb2AV3EPG0vSWLPDSkJBW7XD/uIR0HSDUgDEi/7VDG U3x8Y71tzJ3UFSqJwZ7vudFni16l33IBTpyz0YQ7KQcm1StbFdtSwJWj3FrWoWxCNfs/SWpbHZS 0dSOSnZ+E8jXFX1/Us4Szs9dI6ru5OyK1PjfwlqHGUnqfs9gGJ+9mclaTmdRlhSsMydN29s77N4 EVuE0z+yPz6sjeQ2pGcdGGf2v6tGSltSsl4JXPhX0RkUyj54fHeeasrtG1f+Py6G25M+zi96MW4 j95vYLffqSw6BO1ssftWEfjPsgAqxJoeeaNfrFfdVKoM4DijHEt6ZJGRU= X-Received: by 2002:a05:6512:1304:b0:5a4:f0:c4c4 with SMTP id 2adb3069b0e04-5aa594c1db9mr238224e87.7.1780048745098; Fri, 29 May 2026 02:59:05 -0700 (PDT) Received: from localhost.localdomain ([94.158.61.193]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-39659e2a8b2sm1309011fa.29.2026.05.29.02.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 02:59:04 -0700 (PDT) From: Stepan Ionichev To: wbg@kernel.org Cc: m32285159@gmail.com, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, sozdayvek@gmail.com Subject: [PATCH v3] counter: ti-eqep: use devm for runtime PM to fix probe error path Date: Fri, 29 May 2026 14:58:34 +0500 Message-Id: <20260529095834.2561-1-sozdayvek@gmail.com> X-Mailer: git-send-email 2.33.0.windows.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ti_eqep_probe() enables runtime PM and takes a reference manually, then returns directly via dev_err_probe() if devm_clk_get_enabled() fails, leaking the runtime PM enable and usage count. v2 tried to route that error through a manual cleanup label, but mixing a devm-managed resource (the clock) with a manual pm_runtime unwind is itself wrong: the devm clock release runs after the manual unwind, in the wrong order. Manage the runtime PM with devm instead: devm_pm_runtime_enable() for the enable, pm_runtime_resume_and_get() with a devm action for the get/put. Every probe error path then unwinds through devm in the correct reverse order, and ti_eqep_remove() no longer has to touch runtime PM. Fixes: f213729f6796 ("counter: new TI eQEP driver") Signed-off-by: Stepan Ionichev --- v3: - Manage runtime PM with devm (devm_pm_runtime_enable plus a devm action for pm_runtime_put_sync); remove now-empty PM unwind from ti_eqep_remove() (Andy) - Reword commit message: v2 mixed devm with manual unwind, fix is full devm conversion v2: https://lore.kernel.org/all/20260525152137.7428-1-sozdayvek@gmail.com/ v1: https://lore.kernel.org/all/20260523184448.7609-1-sozdayvek@gmail.com/ drivers/counter/ti-eqep.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c index d21c157e531a..b24c8a29201d 100644 --- a/drivers/counter/ti-eqep.c +++ b/drivers/counter/ti-eqep.c @@ -492,6 +492,11 @@ static const struct regmap_config ti_eqep_regmap16_con= fig =3D { .max_register =3D QCPRDLAT, }; =20 +static void ti_eqep_pm_put(void *dev) +{ + pm_runtime_put_sync(dev); +} + static int ti_eqep_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; @@ -544,19 +549,25 @@ static int ti_eqep_probe(struct platform_device *pdev) * parent PWMSS bus driver. On AM17xx, this comes from the PSC power * domain. */ - pm_runtime_enable(dev); - pm_runtime_get_sync(dev); + err =3D devm_pm_runtime_enable(dev); + if (err) + return err; + + err =3D pm_runtime_resume_and_get(dev); + if (err) + return err; + + err =3D devm_add_action_or_reset(dev, ti_eqep_pm_put, dev); + if (err) + return err; =20 clk =3D devm_clk_get_enabled(dev, NULL); if (IS_ERR(clk)) return dev_err_probe(dev, PTR_ERR(clk), "failed to enable clock\n"); =20 err =3D counter_add(counter); - if (err < 0) { - pm_runtime_put_sync(dev); - pm_runtime_disable(dev); - return err; - } + if (err < 0) + return dev_err_probe(dev, err, "Failed to add counter\n"); =20 return 0; } @@ -564,11 +575,8 @@ static int ti_eqep_probe(struct platform_device *pdev) static void ti_eqep_remove(struct platform_device *pdev) { struct counter_device *counter =3D platform_get_drvdata(pdev); - struct device *dev =3D &pdev->dev; =20 counter_unregister(counter); - pm_runtime_put_sync(dev); - pm_runtime_disable(dev); } =20 static const struct of_device_id ti_eqep_of_match[] =3D { --=20 2.43.0