Re: [PATCH v2 06/17] drm/display/dp_mst: Sanitize payload iteration in drm_dp_mst_dump_topology()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2023-01-31 at 17:05 +0200, Imre Deak wrote:
> Simplify the loop iterating the payloads by using a helper to get a
> payload by its VCPI (keeping the list VCPI sorted). This also removes
> the assumption that the biggest VCPI matches the number of payloads
> (even though this holds now).
> 
> Suggested-by: Ville Syrjälä <ville.syrjala@xxxxxxxxxxxxxxx>
> Cc: Lyude Paul <lyude@xxxxxxxxxx>
> Cc: Ville Syrjälä <ville.syrjala@xxxxxxxxxxxxxxx>
> Signed-off-by: Imre Deak <imre.deak@xxxxxxxxx>
> ---
>  drivers/gpu/drm/display/drm_dp_mst_topology.c | 45 ++++++++++++-------
>  1 file changed, 28 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/gpu/drm/display/drm_dp_mst_topology.c b/drivers/gpu/drm/display/drm_dp_mst_topology.c
> index 8787df19f428b..0c04b96ae614c 100644
> --- a/drivers/gpu/drm/display/drm_dp_mst_topology.c
> +++ b/drivers/gpu/drm/display/drm_dp_mst_topology.c
> @@ -4737,6 +4737,18 @@ static void fetch_monitor_name(struct drm_dp_mst_topology_mgr *mgr,
>  	kfree(mst_edid);
>  }
>  
> +static struct drm_dp_mst_atomic_payload *
> +get_payload_by_vcpi(struct drm_dp_mst_topology_state *mst_state, int vcpi)
> +{
> +	struct drm_dp_mst_atomic_payload *payload;
> +
> +	list_for_each_entry(payload, &mst_state->payloads, next)
> +		if (payload->vcpi == vcpi)
> +			return payload;
> +
> +	return NULL;
> +}
> +
>  /**
>   * drm_dp_mst_dump_topology(): dump topology to seq file.
>   * @m: seq_file to dump output to
> @@ -4748,7 +4760,6 @@ void drm_dp_mst_dump_topology(struct seq_file *m,
>  			      struct drm_dp_mst_topology_mgr *mgr)
>  {
>  	struct drm_dp_mst_topology_state *state;
> -	struct drm_dp_mst_atomic_payload *payload;
>  	int i, ret;
>  
>  	mutex_lock(&mgr->lock);
> @@ -4768,24 +4779,24 @@ void drm_dp_mst_dump_topology(struct seq_file *m,
>  		   state->payload_mask, mgr->max_payloads, state->start_slot, state->pbn_div);
>  
>  	seq_printf(m, "\n| idx | port | vcpi | slots | pbn | dsc |     sink name     |\n");
> -	for (i = 0; i < mgr->max_payloads; i++) {
> -		list_for_each_entry(payload, &state->payloads, next) {
> -			char name[14];
> +	for_each_set_bit(i, (unsigned long *)&state->payload_mask,
> +			 BITS_PER_TYPE(state->payload_mask)) {

Huh, TIL we have a for_each_set_bit() macro. neat.

> +		const struct drm_dp_mst_atomic_payload *payload = get_payload_by_vcpi(state, i + 1);
> +		char name[14];
>  
> -			if (payload->vcpi != i + 1 || payload->delete)
> -				continue;
> +		if (payload->delete)
> +			continue;
>  
> -			fetch_monitor_name(mgr, payload->port, name, sizeof(name));
> -			seq_printf(m, " %5d %6d %6d %02d - %02d %5d %5s %19s\n",
> -				   i,
> -				   payload->port->port_num,
> -				   payload->vcpi,
> -				   payload->vc_start_slot,
> -				   payload->vc_start_slot + payload->time_slots - 1,
> -				   payload->pbn,
> -				   payload->dsc_enabled ? "Y" : "N",
> -				   (*name != 0) ? name : "Unknown");
> -		}
> +		fetch_monitor_name(mgr, payload->port, name, sizeof(name));
> +		seq_printf(m, " %5d %6d %6d %02d - %02d %5d %5s %19s\n",
> +			   i,
> +			   payload->port->port_num,
> +			   payload->vcpi,
> +			   payload->vc_start_slot,
> +			   payload->vc_start_slot + payload->time_slots - 1,
> +			   payload->pbn,
> +			   payload->dsc_enabled ? "Y" : "N",
> +			   (*name != 0) ? name : "Unknown");
>  	}
>  
>  	seq_printf(m, "\n*** DPCD Info ***\n");

-- 
Cheers,
 Lyude Paul (she/her)
 Software Engineer at Red Hat





[Index of Archives]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux