All of lore.kernel.org
 help / color / mirror / Atom feed
From: He Ying <heying24@huawei.com>
To: Maxime Ripard <maxime@cerno.tech>
Cc: <wens@csie.org>, <airlied@linux.ie>, <daniel@ffwll.ch>,
	<jernej.skrabec@gmail.com>, <dri-devel@lists.freedesktop.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-sunxi@lists.linux.dev>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH -V2] drm/sun4i: Grab reference of connector before return connector from sun4i_tcon_get_connector
Date: Wed, 3 Nov 2021 10:26:42 +0800	[thread overview]
Message-ID: <a0871590-62b2-bbf2-d6ab-920abdf20fad@huawei.com> (raw)
In-Reply-To: <20211102150331.526nn2e6oqjbf6ur@gilmour>


在 2021/11/2 23:03, Maxime Ripard 写道:
> Hi,
>
> On Tue, Nov 02, 2021 at 04:46:28AM -0400, He Ying wrote:
>>  From the comments of drm_for_each_connector_iter(), we know
>> that "connector is only valid within the list body, if you
>> want to use connector after calling drm_connector_list_iter_end()
>> then you need to grab your own reference first using
>> drm_connector_get()". So fix the wrong use of connector
>> according to the comments and then call drm_connector_put()
>> after using connector finishes.
>>
>> Signed-off-by: He Ying <heying24@huawei.com>
>> ---
>>
>> V2:
>>   Use proper subject prefix
>>
>>   drivers/gpu/drm/sun4i/sun4i_tcon.c | 18 +++++++++++++-----
>>   1 file changed, 13 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.c b/drivers/gpu/drm/sun4i/sun4i_tcon.c
>> index 9f06dec0fc61..24fa6784ee5f 100644
>> --- a/drivers/gpu/drm/sun4i/sun4i_tcon.c
>> +++ b/drivers/gpu/drm/sun4i/sun4i_tcon.c
>> @@ -47,12 +47,12 @@ static struct drm_connector *sun4i_tcon_get_connector(const struct drm_encoder *
>>   	drm_connector_list_iter_begin(encoder->dev, &iter);
>>   	drm_for_each_connector_iter(connector, &iter)
>>   		if (connector->encoder == encoder) {
>> -			drm_connector_list_iter_end(&iter);
>> -			return connector;
>> +			drm_connector_get(connector);
>> +			break;
>>   		}
>>   	drm_connector_list_iter_end(&iter);
>>   
>> -	return NULL;
>> +	return connector;
> Connector might be uninitialized if we don't find one here

Connector should be NULL if we don't find one. The code is

#define drm_for_each_connector_iter(connector, iter) \
    while ((connector = drm_connector_list_iter_next(iter)))

So, when we don't break from the while body, connector

can only be NULL.

>
>>   }
>>   
>>   static int sun4i_tcon_get_pixel_depth(const struct drm_encoder *encoder)
>> @@ -65,6 +65,7 @@ static int sun4i_tcon_get_pixel_depth(const struct drm_encoder *encoder)
>>   		return -EINVAL;
>>   
>>   	info = &connector->display_info;
>> +	drm_connector_put(connector);
>>   	if (info->num_bus_formats != 1)
> We're still accessing connector->display_info here, but it might have been
> freed already.
Agree. I'll place it after using 'info' finishes in v3.
>
> Maxime

WARNING: multiple messages have this Message-ID (diff)
From: He Ying <heying24@huawei.com>
To: Maxime Ripard <maxime@cerno.tech>
Cc: airlied@linux.ie, linux-kernel@vger.kernel.org,
	dri-devel@lists.freedesktop.org, wens@csie.org,
	jernej.skrabec@gmail.com, linux-sunxi@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH -V2] drm/sun4i: Grab reference of connector before return connector from sun4i_tcon_get_connector
Date: Wed, 3 Nov 2021 10:26:42 +0800	[thread overview]
Message-ID: <a0871590-62b2-bbf2-d6ab-920abdf20fad@huawei.com> (raw)
In-Reply-To: <20211102150331.526nn2e6oqjbf6ur@gilmour>


在 2021/11/2 23:03, Maxime Ripard 写道:
> Hi,
>
> On Tue, Nov 02, 2021 at 04:46:28AM -0400, He Ying wrote:
>>  From the comments of drm_for_each_connector_iter(), we know
>> that "connector is only valid within the list body, if you
>> want to use connector after calling drm_connector_list_iter_end()
>> then you need to grab your own reference first using
>> drm_connector_get()". So fix the wrong use of connector
>> according to the comments and then call drm_connector_put()
>> after using connector finishes.
>>
>> Signed-off-by: He Ying <heying24@huawei.com>
>> ---
>>
>> V2:
>>   Use proper subject prefix
>>
>>   drivers/gpu/drm/sun4i/sun4i_tcon.c | 18 +++++++++++++-----
>>   1 file changed, 13 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.c b/drivers/gpu/drm/sun4i/sun4i_tcon.c
>> index 9f06dec0fc61..24fa6784ee5f 100644
>> --- a/drivers/gpu/drm/sun4i/sun4i_tcon.c
>> +++ b/drivers/gpu/drm/sun4i/sun4i_tcon.c
>> @@ -47,12 +47,12 @@ static struct drm_connector *sun4i_tcon_get_connector(const struct drm_encoder *
>>   	drm_connector_list_iter_begin(encoder->dev, &iter);
>>   	drm_for_each_connector_iter(connector, &iter)
>>   		if (connector->encoder == encoder) {
>> -			drm_connector_list_iter_end(&iter);
>> -			return connector;
>> +			drm_connector_get(connector);
>> +			break;
>>   		}
>>   	drm_connector_list_iter_end(&iter);
>>   
>> -	return NULL;
>> +	return connector;
> Connector might be uninitialized if we don't find one here

Connector should be NULL if we don't find one. The code is

#define drm_for_each_connector_iter(connector, iter) \
    while ((connector = drm_connector_list_iter_next(iter)))

So, when we don't break from the while body, connector

can only be NULL.

>
>>   }
>>   
>>   static int sun4i_tcon_get_pixel_depth(const struct drm_encoder *encoder)
>> @@ -65,6 +65,7 @@ static int sun4i_tcon_get_pixel_depth(const struct drm_encoder *encoder)
>>   		return -EINVAL;
>>   
>>   	info = &connector->display_info;
>> +	drm_connector_put(connector);
>>   	if (info->num_bus_formats != 1)
> We're still accessing connector->display_info here, but it might have been
> freed already.
Agree. I'll place it after using 'info' finishes in v3.
>
> Maxime

WARNING: multiple messages have this Message-ID (diff)
From: He Ying <heying24@huawei.com>
To: Maxime Ripard <maxime@cerno.tech>
Cc: <wens@csie.org>, <airlied@linux.ie>, <daniel@ffwll.ch>,
	<jernej.skrabec@gmail.com>, <dri-devel@lists.freedesktop.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-sunxi@lists.linux.dev>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH -V2] drm/sun4i: Grab reference of connector before return connector from sun4i_tcon_get_connector
Date: Wed, 3 Nov 2021 10:26:42 +0800	[thread overview]
Message-ID: <a0871590-62b2-bbf2-d6ab-920abdf20fad@huawei.com> (raw)
In-Reply-To: <20211102150331.526nn2e6oqjbf6ur@gilmour>


在 2021/11/2 23:03, Maxime Ripard 写道:
> Hi,
>
> On Tue, Nov 02, 2021 at 04:46:28AM -0400, He Ying wrote:
>>  From the comments of drm_for_each_connector_iter(), we know
>> that "connector is only valid within the list body, if you
>> want to use connector after calling drm_connector_list_iter_end()
>> then you need to grab your own reference first using
>> drm_connector_get()". So fix the wrong use of connector
>> according to the comments and then call drm_connector_put()
>> after using connector finishes.
>>
>> Signed-off-by: He Ying <heying24@huawei.com>
>> ---
>>
>> V2:
>>   Use proper subject prefix
>>
>>   drivers/gpu/drm/sun4i/sun4i_tcon.c | 18 +++++++++++++-----
>>   1 file changed, 13 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.c b/drivers/gpu/drm/sun4i/sun4i_tcon.c
>> index 9f06dec0fc61..24fa6784ee5f 100644
>> --- a/drivers/gpu/drm/sun4i/sun4i_tcon.c
>> +++ b/drivers/gpu/drm/sun4i/sun4i_tcon.c
>> @@ -47,12 +47,12 @@ static struct drm_connector *sun4i_tcon_get_connector(const struct drm_encoder *
>>   	drm_connector_list_iter_begin(encoder->dev, &iter);
>>   	drm_for_each_connector_iter(connector, &iter)
>>   		if (connector->encoder == encoder) {
>> -			drm_connector_list_iter_end(&iter);
>> -			return connector;
>> +			drm_connector_get(connector);
>> +			break;
>>   		}
>>   	drm_connector_list_iter_end(&iter);
>>   
>> -	return NULL;
>> +	return connector;
> Connector might be uninitialized if we don't find one here

Connector should be NULL if we don't find one. The code is

#define drm_for_each_connector_iter(connector, iter) \
    while ((connector = drm_connector_list_iter_next(iter)))

So, when we don't break from the while body, connector

can only be NULL.

>
>>   }
>>   
>>   static int sun4i_tcon_get_pixel_depth(const struct drm_encoder *encoder)
>> @@ -65,6 +65,7 @@ static int sun4i_tcon_get_pixel_depth(const struct drm_encoder *encoder)
>>   		return -EINVAL;
>>   
>>   	info = &connector->display_info;
>> +	drm_connector_put(connector);
>>   	if (info->num_bus_formats != 1)
> We're still accessing connector->display_info here, but it might have been
> freed already.
Agree. I'll place it after using 'info' finishes in v3.
>
> Maxime

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-11-03  2:44 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-01  6:29 [PATCH] drm: Grab reference of connector before return connector from sun4i_tcon_get_connector He Ying
2021-11-01  6:29 ` He Ying
2021-11-01  6:29 ` He Ying
2021-11-01 13:02 ` Jani Nikula
2021-11-01 13:02   ` Jani Nikula
2021-11-01 13:02   ` Jani Nikula
2021-11-02  2:48   ` He Ying
2021-11-02  2:48     ` He Ying
2021-11-02  2:48     ` He Ying
2021-11-02  8:37     ` Jani Nikula
2021-11-02  8:37       ` Jani Nikula
2021-11-02  8:37       ` Jani Nikula
2021-11-02  8:46     ` [PATCH -V2] drm/sun4i: " He Ying
2021-11-02  8:46       ` He Ying
2021-11-02  8:46       ` He Ying
2021-11-02 15:03       ` Maxime Ripard
2021-11-02 15:03         ` Maxime Ripard
2021-11-02 15:03         ` Maxime Ripard
2021-11-03  2:26         ` He Ying [this message]
2021-11-03  2:26           ` He Ying
2021-11-03  2:26           ` He Ying

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a0871590-62b2-bbf2-d6ab-920abdf20fad@huawei.com \
    --to=heying24@huawei.com \
    --cc=airlied@linux.ie \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jernej.skrabec@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=maxime@cerno.tech \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.