From nobody Mon Nov 25 14:33:17 2024 Received: from smtp.smtpout.orange.fr (smtp-18.smtpout.orange.fr [80.12.242.18]) (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 6859C217F2E; Sat, 26 Oct 2024 06:32:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.12.242.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729924383; cv=none; b=im1HcXQQeweKs+xWF3jr97p2nVODG1VCYEB7OWTcBvibWv1PiU4HxEn256y7LUzSTVHiifES/PtwK/2DjYpkGRqMALzgLiSukWmZetgXT0VxkOWg4AI8rkLbIHCF/YKSk0o/c/r0CcOJ4iSn+L9q/gsmHfBcwjafBdFMW9rLI5E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729924383; c=relaxed/simple; bh=agr57+TwKsLYZRR5ZaPF7RExp8eb0fp9/mzsJ9nUsqY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=t5gsYzFz16/NnWY0wqUy+UrUXrP8elInYz526oYB1w3H/6GWp0ZMW7hu2qIXIPnH6ZP+uHlwxQyyVedkzJCTV58QGsKqizx1TVGp9Wm84LUjBHrrRJRJfkGcNvaalI7fYSha0e37bo7PE9LMTg3phNdDgup4I+2fZPlTyyMggsg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr; spf=pass smtp.mailfrom=wanadoo.fr; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b=tFs7N6QD; arc=none smtp.client-ip=80.12.242.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b="tFs7N6QD" Received: from localhost.localdomain ([90.11.132.44]) by smtp.orange.fr with ESMTPA id 4aM1tR7nLgeRP4aM1tvlXG; Sat, 26 Oct 2024 08:32:57 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1729924377; bh=4QS1A65O3hsr8uWMktbnBm+HEJ1CiTpjN/zqDqUf/lw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=tFs7N6QDolaDk7ESBYl8GFFTn+5HZ/WlloVaEE1Y7G7haduNLJhW4WvAmzayQlTk8 sBsujEPYlcSb7F4Rd3UUj71cECce5/uCKSvSzHW5kHcHcB9aFWzTEcFh8rWPX2V1c+ wRCLMqnZaTXU/Zh7uRoNPJPGwKWmslXSMdxZoDce5qRpzkpyQLu+N4rjQmaY7QwTpW Xuzb4TAXU1JEA0OScvK0Toeoz40tq3UVsrTjqi2zlImtLPe6n0iOAUs6FIaiGyCiiH AP4vXVXM2RaMwlkQO+T1+HAFWi8acVfhEOaxQy8YGNekW8fCHmpKDVoUgqPFqXzvde 2rCMO7Ksvs41w== X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 26 Oct 2024 08:32:57 +0200 X-ME-IP: 90.11.132.44 From: Christophe JAILLET To: Alex Lanzano , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Dmitry Baryshkov , Mehdi Djait Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , dri-devel@lists.freedesktop.org, linux-pwm@vger.kernel.org Subject: [PATCH] drm/tiny: Fix some error handling paths in sharp_memory_probe() Date: Sat, 26 Oct 2024 08:32:36 +0200 Message-ID: X-Mailer: git-send-email 2.47.0 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" If an error occurs after allocating resources based on which "sharp,vcom-mode" is used, then these resources must be released, as already done in the .remove() function. Use 2 new devm_add_action_or_reset() for that and simplify code accordingly. Fixes: b8f9f21716fe ("drm/tiny: Add driver for Sharp Memory LCD") Signed-off-by: Christophe JAILLET Reviewed-by: Alex Lanzano Tested-by: Alex Lanzano --- Compile tested only --- drivers/gpu/drm/tiny/sharp-memory.c | 66 ++++++++++++++--------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/drivers/gpu/drm/tiny/sharp-memory.c b/drivers/gpu/drm/tiny/sha= rp-memory.c index 2d2315bd6aef..01d1ce2462e1 100644 --- a/drivers/gpu/drm/tiny/sharp-memory.c +++ b/drivers/gpu/drm/tiny/sharp-memory.c @@ -48,12 +48,6 @@ enum sharp_memory_model { LS044Q7DH01, }; =20 -enum sharp_memory_vcom_mode { - SHARP_MEMORY_SOFTWARE_VCOM, - SHARP_MEMORY_EXTERNAL_VCOM, - SHARP_MEMORY_PWM_VCOM -}; - struct sharp_memory_device { struct drm_device drm; struct spi_device *spi; @@ -67,10 +61,6 @@ struct sharp_memory_device { =20 struct gpio_desc *enable_gpio; =20 - struct task_struct *sw_vcom_signal; - struct pwm_device *pwm_vcom_signal; - - enum sharp_memory_vcom_mode vcom_mode; u8 vcom; =20 u32 pitch; @@ -500,25 +490,41 @@ static int sharp_memory_pipe_init(struct drm_device *= dev, return drm_connector_attach_encoder(connector, encoder); } =20 +static void sharp_memory_stop_kthread(void *data) +{ + struct task_struct *task =3D data; + + kthread_stop(task); +} + +static void sharp_memory_disable_pwm(void *data) +{ + struct pwm_device *pwm =3D data; + + pwm_disable(pwm); +} + static int sharp_memory_init_pwm_vcom_signal(struct sharp_memory_device *s= md) { int ret; struct device *dev =3D &smd->spi->dev; + struct pwm_device *pwm_vcom_signal; struct pwm_state pwm_state; =20 - smd->pwm_vcom_signal =3D devm_pwm_get(dev, NULL); - if (IS_ERR(smd->pwm_vcom_signal)) - return dev_err_probe(dev, PTR_ERR(smd->pwm_vcom_signal), + pwm_vcom_signal =3D devm_pwm_get(dev, NULL); + if (IS_ERR(pwm_vcom_signal)) + return dev_err_probe(dev, PTR_ERR(pwm_vcom_signal), "Could not get pwm device\n"); =20 - pwm_init_state(smd->pwm_vcom_signal, &pwm_state); + pwm_init_state(pwm_vcom_signal, &pwm_state); pwm_set_relative_duty_cycle(&pwm_state, 1, 10); pwm_state.enabled =3D true; - ret =3D pwm_apply_might_sleep(smd->pwm_vcom_signal, &pwm_state); + ret =3D pwm_apply_might_sleep(pwm_vcom_signal, &pwm_state); if (ret) return dev_err_probe(dev, -EINVAL, "Could not apply pwm state\n"); =20 - return 0; + return devm_add_action_or_reset(dev, sharp_memory_disable_pwm, + pwm_vcom_signal); } =20 static int sharp_memory_probe(struct spi_device *spi) @@ -595,15 +601,20 @@ static int sharp_memory_probe(struct spi_device *spi) "Unable to find sharp,vcom-mode node in device tree\n"); =20 if (!strcmp("software", vcom_mode_str)) { - smd->vcom_mode =3D SHARP_MEMORY_SOFTWARE_VCOM; - smd->sw_vcom_signal =3D kthread_run(sharp_memory_sw_vcom_signal_thread, - smd, "sw_vcom_signal"); + struct task_struct *sw_vcom_signal; + + sw_vcom_signal =3D kthread_run(sharp_memory_sw_vcom_signal_thread, + smd, "sw_vcom_signal"); + + ret =3D devm_add_action_or_reset(dev, sharp_memory_stop_kthread, + sw_vcom_signal); + if (ret) + return ret; =20 } else if (!strcmp("external", vcom_mode_str)) { - smd->vcom_mode =3D SHARP_MEMORY_EXTERNAL_VCOM; + /* empty */ =20 } else if (!strcmp("pwm", vcom_mode_str)) { - smd->vcom_mode =3D SHARP_MEMORY_PWM_VCOM; ret =3D sharp_memory_init_pwm_vcom_signal(smd); if (ret) return ret; @@ -640,19 +651,6 @@ static void sharp_memory_remove(struct spi_device *spi) =20 drm_dev_unplug(&smd->drm); drm_atomic_helper_shutdown(&smd->drm); - - switch (smd->vcom_mode) { - case SHARP_MEMORY_SOFTWARE_VCOM: - kthread_stop(smd->sw_vcom_signal); - break; - - case SHARP_MEMORY_EXTERNAL_VCOM: - break; - - case SHARP_MEMORY_PWM_VCOM: - pwm_disable(smd->pwm_vcom_signal); - break; - } } =20 static struct spi_driver sharp_memory_spi_driver =3D { --=20 2.47.0