diff mbox series

[08/12] drm/client: Extract drm_connector_first_mode()

Message ID 20240404203336.10454-9-ville.syrjala@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series drm/client: Use after free and debug improvements | expand

Commit Message

Ville Syrjälä April 4, 2024, 8:33 p.m. UTC
From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Use a consistent method for picking the first mode from the
connnector's mode list.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/drm_client_modeset.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

Comments

Jani Nikula April 5, 2024, 8:26 a.m. UTC | #1
On Thu, 04 Apr 2024, Ville Syrjala <ville.syrjala@linux.intel.com> wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> Use a consistent method for picking the first mode from the
> connnector's mode list.

Patches 1-8 inclusive are

Reviewed-by: Jani Nikula <jani.nikula@intel.com>

>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>  drivers/gpu/drm/drm_client_modeset.c | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_client_modeset.c b/drivers/gpu/drm/drm_client_modeset.c
> index 08fc896885dd..1fba6cd8d761 100644
> --- a/drivers/gpu/drm/drm_client_modeset.c
> +++ b/drivers/gpu/drm/drm_client_modeset.c
> @@ -159,6 +159,13 @@ drm_connector_preferred_mode(struct drm_connector *connector, int width, int hei
>  	return NULL;
>  }
>  
> +static const struct drm_display_mode *
> +drm_connector_first_mode(struct drm_connector *connector)
> +{
> +	return list_first_entry_or_null(&connector->modes,
> +					struct drm_display_mode, head);
> +}
> +
>  static const struct drm_display_mode *
>  drm_connector_pick_cmdline_mode(struct drm_connector *connector)
>  {
> @@ -439,10 +446,8 @@ static bool drm_client_target_preferred(struct drm_connector *connectors[],
>  			modes[i] = drm_connector_preferred_mode(connector, width, height);
>  		}
>  		/* No preferred modes, pick one off the list */
> -		if (!modes[i] && !list_empty(&connector->modes)) {
> -			list_for_each_entry(modes[i], &connector->modes, head)
> -				break;
> -		}
> +		if (!modes[i])
> +			modes[i] = drm_connector_first_mode(connector);
>  		/*
>  		 * In case of tiled mode if all tiles not present fallback to
>  		 * first available non tiled mode.
> @@ -684,9 +689,7 @@ static bool drm_client_firmware_config(struct drm_client_dev *client,
>  		if (!modes[i] && !list_empty(&connector->modes)) {
>  			DRM_DEBUG_KMS("using first mode listed on connector %s\n",
>  				      connector->name);
> -			modes[i] = list_first_entry(&connector->modes,
> -						    struct drm_display_mode,
> -						    head);
> +			modes[i] = drm_connector_first_mode(connector);
>  		}
>  
>  		/* last resort: use current mode */
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_client_modeset.c b/drivers/gpu/drm/drm_client_modeset.c
index 08fc896885dd..1fba6cd8d761 100644
--- a/drivers/gpu/drm/drm_client_modeset.c
+++ b/drivers/gpu/drm/drm_client_modeset.c
@@ -159,6 +159,13 @@  drm_connector_preferred_mode(struct drm_connector *connector, int width, int hei
 	return NULL;
 }
 
+static const struct drm_display_mode *
+drm_connector_first_mode(struct drm_connector *connector)
+{
+	return list_first_entry_or_null(&connector->modes,
+					struct drm_display_mode, head);
+}
+
 static const struct drm_display_mode *
 drm_connector_pick_cmdline_mode(struct drm_connector *connector)
 {
@@ -439,10 +446,8 @@  static bool drm_client_target_preferred(struct drm_connector *connectors[],
 			modes[i] = drm_connector_preferred_mode(connector, width, height);
 		}
 		/* No preferred modes, pick one off the list */
-		if (!modes[i] && !list_empty(&connector->modes)) {
-			list_for_each_entry(modes[i], &connector->modes, head)
-				break;
-		}
+		if (!modes[i])
+			modes[i] = drm_connector_first_mode(connector);
 		/*
 		 * In case of tiled mode if all tiles not present fallback to
 		 * first available non tiled mode.
@@ -684,9 +689,7 @@  static bool drm_client_firmware_config(struct drm_client_dev *client,
 		if (!modes[i] && !list_empty(&connector->modes)) {
 			DRM_DEBUG_KMS("using first mode listed on connector %s\n",
 				      connector->name);
-			modes[i] = list_first_entry(&connector->modes,
-						    struct drm_display_mode,
-						    head);
+			modes[i] = drm_connector_first_mode(connector);
 		}
 
 		/* last resort: use current mode */