diff mbox

drm/nouveau: remove redundant null check on array mstm->msto

Message ID 20170817103752.16440-1-colin.king@canonical.com (mailing list archive)
State New, archived
Headers show

Commit Message

Colin King Aug. 17, 2017, 10:37 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

The check to see if mstm->msto is null is redundant because it is
an array and hence can never be null.  Remove the redundant check.

Detected by CoverityScan, CID#1375915 ("Array compared against 0")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/gpu/drm/nouveau/nv50_display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Emil Velikov Aug. 17, 2017, 12:21 p.m. UTC | #1
On 17 August 2017 at 11:37, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> The check to see if mstm->msto is null is redundant because it is
> an array and hence can never be null.  Remove the redundant check.
>
> Detected by CoverityScan, CID#1375915 ("Array compared against 0")
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/gpu/drm/nouveau/nv50_display.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/nouveau/nv50_display.c b/drivers/gpu/drm/nouveau/nv50_display.c
> index f7b4326a4641..51e9081b95a0 100644
> --- a/drivers/gpu/drm/nouveau/nv50_display.c
> +++ b/drivers/gpu/drm/nouveau/nv50_display.c
> @@ -3141,7 +3141,7 @@ nv50_mstc_new(struct nv50_mstm *mstm, struct drm_dp_mst_port *port,
>         mstc->connector.funcs->reset(&mstc->connector);
>         nouveau_conn_attach_properties(&mstc->connector);
>
> -       for (i = 0; i < ARRAY_SIZE(mstm->msto) && mstm->msto; i++)
> +       for (i = 0; i < ARRAY_SIZE(mstm->msto); i++)
I think that should be mstm->msto[i]. After all we are dereferencing
the pointer, so we don't want to crash.

>                 drm_mode_connector_attach_encoder(&mstc->connector, &mstm->msto[i]->encoder);

-Emil
Colin King Aug. 17, 2017, 1:02 p.m. UTC | #2
On 17/08/17 13:21, Emil Velikov wrote:
> On 17 August 2017 at 11:37, Colin King <colin.king@canonical.com> wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> The check to see if mstm->msto is null is redundant because it is
>> an array and hence can never be null.  Remove the redundant check.
>>
>> Detected by CoverityScan, CID#1375915 ("Array compared against 0")
>>
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>> ---
>>  drivers/gpu/drm/nouveau/nv50_display.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/nouveau/nv50_display.c b/drivers/gpu/drm/nouveau/nv50_display.c
>> index f7b4326a4641..51e9081b95a0 100644
>> --- a/drivers/gpu/drm/nouveau/nv50_display.c
>> +++ b/drivers/gpu/drm/nouveau/nv50_display.c
>> @@ -3141,7 +3141,7 @@ nv50_mstc_new(struct nv50_mstm *mstm, struct drm_dp_mst_port *port,
>>         mstc->connector.funcs->reset(&mstc->connector);
>>         nouveau_conn_attach_properties(&mstc->connector);
>>
>> -       for (i = 0; i < ARRAY_SIZE(mstm->msto) && mstm->msto; i++)
>> +       for (i = 0; i < ARRAY_SIZE(mstm->msto); i++)
> I think that should be mstm->msto[i]. After all we are dereferencing
> the pointer, so we don't want to crash.

Yes, that makes far more sense. I'll send a V2. Thanks Emil.

> 
>>                 drm_mode_connector_attach_encoder(&mstc->connector, &mstm->msto[i]->encoder);
> 
> -Emil
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
diff mbox

Patch

diff --git a/drivers/gpu/drm/nouveau/nv50_display.c b/drivers/gpu/drm/nouveau/nv50_display.c
index f7b4326a4641..51e9081b95a0 100644
--- a/drivers/gpu/drm/nouveau/nv50_display.c
+++ b/drivers/gpu/drm/nouveau/nv50_display.c
@@ -3141,7 +3141,7 @@  nv50_mstc_new(struct nv50_mstm *mstm, struct drm_dp_mst_port *port,
 	mstc->connector.funcs->reset(&mstc->connector);
 	nouveau_conn_attach_properties(&mstc->connector);
 
-	for (i = 0; i < ARRAY_SIZE(mstm->msto) && mstm->msto; i++)
+	for (i = 0; i < ARRAY_SIZE(mstm->msto); i++)
 		drm_mode_connector_attach_encoder(&mstc->connector, &mstm->msto[i]->encoder);
 
 	drm_object_attach_property(&mstc->connector.base, dev->mode_config.path_property, 0);