diff mbox series

[2/8] drm/panel: do not return negative error codes from drm_panel_get_modes()

Message ID 79f559b72d8c493940417304e222a4b04dfa19c4.1709913674.git.jani.nikula@intel.com (mailing list archive)
State New, archived
Headers show
Series drm: fix .get_modes() return values | expand

Commit Message

Jani Nikula March 8, 2024, 4:03 p.m. UTC
None of the callers of drm_panel_get_modes() expect it to return
negative error codes. Either they propagate the return value in their
struct drm_connector_helper_funcs .get_modes() hook (which is also not
supposed to return negative codes), or add it to other counts leading to
bogus values.

On the other hand, many of the struct drm_panel_funcs .get_modes() hooks
do return negative error codes, so handle them gracefully instead of
propagating further.

Return 0 for no modes, whatever the reason.

Cc: Neil Armstrong <neil.armstrong@linaro.org>
Cc: Jessica Zhang <quic_jesszhan@quicinc.com>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: stable@vger.kernel.org
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 drivers/gpu/drm/drm_panel.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Comments

Jessica Zhang March 8, 2024, 4:52 p.m. UTC | #1
On 3/8/2024 8:03 AM, Jani Nikula wrote:
> None of the callers of drm_panel_get_modes() expect it to return
> negative error codes. Either they propagate the return value in their
> struct drm_connector_helper_funcs .get_modes() hook (which is also not
> supposed to return negative codes), or add it to other counts leading to
> bogus values.
> 
> On the other hand, many of the struct drm_panel_funcs .get_modes() hooks
> do return negative error codes, so handle them gracefully instead of
> propagating further.
> 
> Return 0 for no modes, whatever the reason.
> 
> Cc: Neil Armstrong <neil.armstrong@linaro.org>
> Cc: Jessica Zhang <quic_jesszhan@quicinc.com>
> Cc: Sam Ravnborg <sam@ravnborg.org>
> Cc: stable@vger.kernel.org
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> ---
>   drivers/gpu/drm/drm_panel.c | 17 +++++++++++------
>   1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
> index e814020bbcd3..cfbe020de54e 100644
> --- a/drivers/gpu/drm/drm_panel.c
> +++ b/drivers/gpu/drm/drm_panel.c
> @@ -274,19 +274,24 @@ EXPORT_SYMBOL(drm_panel_disable);
>    * The modes probed from the panel are automatically added to the connector
>    * that the panel is attached to.
>    *
> - * Return: The number of modes available from the panel on success or a
> - * negative error code on failure.
> + * Return: The number of modes available from the panel on success, or 0 on
> + * failure (no modes).
>    */
>   int drm_panel_get_modes(struct drm_panel *panel,
>   			struct drm_connector *connector)
>   {
>   	if (!panel)
> -		return -EINVAL;
> +		return 0;
>   
> -	if (panel->funcs && panel->funcs->get_modes)
> -		return panel->funcs->get_modes(panel, connector);
> +	if (panel->funcs && panel->funcs->get_modes) {
> +		int num;
>   
> -	return -EOPNOTSUPP;
> +		num = panel->funcs->get_modes(panel, connector);
> +		if (num > 0)
> +			return num;

Hi Jani,

The change LGTM:

Reviewed-by: Jessica Zhang <quic_jesszhan@quicinc.com>

Thanks,

Jessica Zhang

> +	}
> +
> +	return 0;
>   }
>   EXPORT_SYMBOL(drm_panel_get_modes);
>   
> -- 
> 2.39.2
>
Neil Armstrong March 11, 2024, 8:23 a.m. UTC | #2
On 08/03/2024 17:03, Jani Nikula wrote:
> None of the callers of drm_panel_get_modes() expect it to return
> negative error codes. Either they propagate the return value in their
> struct drm_connector_helper_funcs .get_modes() hook (which is also not
> supposed to return negative codes), or add it to other counts leading to
> bogus values.
> 
> On the other hand, many of the struct drm_panel_funcs .get_modes() hooks
> do return negative error codes, so handle them gracefully instead of
> propagating further.
> 
> Return 0 for no modes, whatever the reason.
> 
> Cc: Neil Armstrong <neil.armstrong@linaro.org>
> Cc: Jessica Zhang <quic_jesszhan@quicinc.com>
> Cc: Sam Ravnborg <sam@ravnborg.org>
> Cc: stable@vger.kernel.org
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> ---
>   drivers/gpu/drm/drm_panel.c | 17 +++++++++++------
>   1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
> index e814020bbcd3..cfbe020de54e 100644
> --- a/drivers/gpu/drm/drm_panel.c
> +++ b/drivers/gpu/drm/drm_panel.c
> @@ -274,19 +274,24 @@ EXPORT_SYMBOL(drm_panel_disable);
>    * The modes probed from the panel are automatically added to the connector
>    * that the panel is attached to.
>    *
> - * Return: The number of modes available from the panel on success or a
> - * negative error code on failure.
> + * Return: The number of modes available from the panel on success, or 0 on
> + * failure (no modes).
>    */
>   int drm_panel_get_modes(struct drm_panel *panel,
>   			struct drm_connector *connector)
>   {
>   	if (!panel)
> -		return -EINVAL;
> +		return 0;
>   
> -	if (panel->funcs && panel->funcs->get_modes)
> -		return panel->funcs->get_modes(panel, connector);
> +	if (panel->funcs && panel->funcs->get_modes) {
> +		int num;
>   
> -	return -EOPNOTSUPP;
> +		num = panel->funcs->get_modes(panel, connector);
> +		if (num > 0)
> +			return num;
> +	}
> +
> +	return 0;
>   }
>   EXPORT_SYMBOL(drm_panel_get_modes);
>   

Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
index e814020bbcd3..cfbe020de54e 100644
--- a/drivers/gpu/drm/drm_panel.c
+++ b/drivers/gpu/drm/drm_panel.c
@@ -274,19 +274,24 @@  EXPORT_SYMBOL(drm_panel_disable);
  * The modes probed from the panel are automatically added to the connector
  * that the panel is attached to.
  *
- * Return: The number of modes available from the panel on success or a
- * negative error code on failure.
+ * Return: The number of modes available from the panel on success, or 0 on
+ * failure (no modes).
  */
 int drm_panel_get_modes(struct drm_panel *panel,
 			struct drm_connector *connector)
 {
 	if (!panel)
-		return -EINVAL;
+		return 0;
 
-	if (panel->funcs && panel->funcs->get_modes)
-		return panel->funcs->get_modes(panel, connector);
+	if (panel->funcs && panel->funcs->get_modes) {
+		int num;
 
-	return -EOPNOTSUPP;
+		num = panel->funcs->get_modes(panel, connector);
+		if (num > 0)
+			return num;
+	}
+
+	return 0;
 }
 EXPORT_SYMBOL(drm_panel_get_modes);