drm/nouveau/clk: avoid potential null-dereference
Subsystems (3)
PATCH 1/1 drm/nouveau/clk: avoid potential null-dereference
We have to check pointer before usage.
--- drivers/gpu/drm/nouveau/core/subdev/clock/base.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/nouveau/core/subdev/clock/base.c +3 -1
@@ -322,7 +322,6 @@ nouveau_pstate_new(struct nouveau_clock *clk, int idx)return 0 ; pstate =kzalloc (sizeof (*pstate),GFP_KERNEL ); - cstate = &pstate->base;if (!pstate)return -ENOMEM ;
@@ -330,6 +329,9 @@ nouveau_pstate_new(struct nouveau_clock *clk, int idx) pstate->pstate = perfE.pstate; pstate->fanspeed = perfE.fanspeed; + + cstate = &pstate->base; + cstate->voltage = perfE.voltage; cstate->domain[nv_clk_src_core] = perfE.core; cstate->domain[nv_clk_src_shader] = perfE.shader;
Signature · 6 lines
1.8.3.101.g727a46b _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 13 lines · Andy Shevchenko
We have to check pointer before usage.
Reported-by Andrey Karpov <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/gpu/drm/nouveau/core/subdev/clock/base.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/nouveau/core/subdev/clock/base.c +0
-0
drivers/gpu/drm/nouveau/core/subdev/clock/base.c nouveau_pstate_new(struct nouveau_clock *clk, int idx) · line 325
Quoted 4 lines
drivers/gpu/drm/nouveau/core/subdev/clock/base.c +0
-1@@ -322,7 +322,6 @@ nouveau_pstate_new(struct nouveau_clock *clk, int idx)return 0 ; pstate =kzalloc (sizeof (*pstate),GFP_KERNEL ); - cstate = &pstate->base;
What's wrong with this line? If pstate == NULL, &pstate->base == NULL as well and we return.
Quoted 16 lines
drivers/gpu/drm/nouveau/core/subdev/clock/base.c +3
-1if (!pstate)return -ENOMEM ;@@ -330,6 +329,9 @@ nouveau_pstate_new(struct nouveau_clock *clk, int idx) pstate->pstate = perfE.pstate; pstate->fanspeed = perfE.fanspeed; + + cstate = &pstate->base; + cstate->voltage = perfE.voltage; cstate->domain[nv_clk_src_core] = perfE.core; cstate->domain[nv_clk_src_shader] = perfE.shader; --1.8.3.101.g727a46b
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 17 lines · Ilia Mirkin
Quoted 15 lines · Andy Shevchenko
We have to check pointer before usage.
Reported-by Andrey Karpov <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/gpu/drm/nouveau/core/subdev/clock/base.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/nouveau/core/subdev/clock/base.c +0
-0@@ -322,7 +322,6 @@ nouveau_pstate_new(struct nouveau_clock *clk, int idx)return 0 ;
Quoted 4 lines
drivers/gpu/drm/nouveau/core/subdev/clock/base.c nouveau_pstate_new(struct nouveau_clock *clk, int idx) · line 325
Quoted 2 lines
drivers/gpu/drm/nouveau/core/subdev/clock/base.c +0
-1pstate =kzalloc (sizeof (*pstate),GFP_KERNEL ); - cstate = &pstate->base;What's wrong with this line? If pstate == NULL,
&pstate->base== NULL as well and we return.
If pstate == NULL (kzalloc returned NULL), pstate->base triggers a null pointer deference error?
Thanks,
Vince
Quoted 17 lines
Quoted 17 lines
drivers/gpu/drm/nouveau/core/subdev/clock/base.c +3
-1if (!pstate)return -ENOMEM ;@@ -330,6 +329,9 @@ nouveau_pstate_new(struct nouveau_clock *clk, int idx) pstate->pstate = perfE.pstate; pstate->fanspeed = perfE.fanspeed; + + cstate = &pstate->base; + cstate->voltage = perfE.voltage; cstate->domain[nv_clk_src_core] = perfE.core; cstate->domain[nv_clk_src_shader] = perfE.shader; --1.8.3.101.g727a46b
Quoted 8 lines
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 29 lines · Vince Hsu
Quoted 21 lines · Ilia Mirkin
Quoted 18 lines · Andy Shevchenko
We have to check pointer before usage.
Reported-by Andrey Karpov <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/gpu/drm/nouveau/core/subdev/clock/base.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/nouveau/core/subdev/clock/base.c +0
-0@@ -322,7 +322,6 @@ nouveau_pstate_new(struct nouveau_clock *clk, int idx)return 0 ;Quoted 5 lines
drivers/gpu/drm/nouveau/core/subdev/clock/base.c nouveau_pstate_new(struct nouveau_clock *clk, int idx) · line 325
Quoted 2 lines
drivers/gpu/drm/nouveau/core/subdev/clock/base.c +0
-1pstate =kzalloc (sizeof (*pstate),GFP_KERNEL ); - cstate = &pstate->base;What's wrong with this line? If pstate == NULL,
&pstate->base== NULL as well and we return.
Quoted 3 lines
If pstate == NULL (kzalloc returned NULL),
pstate->basetriggers a null pointer
deference error?
Where do you see "pstate->base"? I only see "&pstate->base" which merely computes an offset into a structure... No reason to dereference pstate.
-ilia
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 25 lines · Ilia Mirkin
Quoted 24 lines · Vince Hsu
Quoted 23 lines · Ilia Mirkin
Quoted 14 lines · Andy Shevchenko
We have to check pointer before usage.
Reported-by Andrey Karpov <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/gpu/drm/nouveau/core/subdev/clock/base.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/nouveau/core/subdev/clock/base.c +0
-0drivers/gpu/drm/nouveau/core/subdev/clock/base.c nouveau_pstate_new(struct nouveau_clock *clk, int · line 326
Quoted 5 lines
drivers/gpu/drm/nouveau/core/subdev/clock/base.c +0
-1@@ -322,7 +322,6 @@ nouveau_pstate_new(struct nouveau_clock *clk, int idx)return 0 ; pstate =kzalloc (sizeof (*pstate),GFP_KERNEL ); - cstate = &pstate->base;What's wrong with this line? If pstate == NULL,
&pstate->base== NULL as well and we return.
Quoted 6 lines
Quoted 3 lines
If pstate == NULL (kzalloc returned NULL),
pstate->basetriggers a null pointer
deference error?Where do you see "
pstate->base"? I only see "&pstate->base" which merely computes an offset into a structure... No reason to dereference pstate.
Sorry that I don't quite understand. We do need deference pstate to get the member base which has type nouveau_cstate, and then assign the address of base to cstate for later use.
struct nouveau_pstate {
struct list_head head;
struct list_head list; /* c-states */
struct nouveau_cstate base;
u8 pstate;
u8 fanspeed;
};Thanks,
Vince
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 44 lines · Vince Hsu
Quoted 31 lines · Ilia Mirkin
Quoted 29 lines · Vince Hsu
Quoted 26 lines · Ilia Mirkin
Quoted 15 lines · Andy Shevchenko
We have to check pointer before usage.
Reported-by Andrey Karpov <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/gpu/drm/nouveau/core/subdev/clock/base.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/nouveau/core/subdev/clock/base.c +0
-0drivers/gpu/drm/nouveau/core/subdev/clock/base.c nouveau_pstate_new(struct nouveau_clock *clk, int · line 326
Quoted 5 lines
drivers/gpu/drm/nouveau/core/subdev/clock/base.c +0
-1@@ -322,7 +322,6 @@ nouveau_pstate_new(struct nouveau_clock *clk, int idx)return 0 ; pstate =kzalloc (sizeof (*pstate),GFP_KERNEL ); - cstate = &pstate->base;What's wrong with this line? If pstate == NULL,
&pstate->base== NULL as well and we return.Quoted 7 lines
Quoted 3 lines
If pstate == NULL (kzalloc returned NULL),
pstate->basetriggers a null pointer
deference error?Where do you see "
pstate->base"? I only see "&pstate->base" which merely computes an offset into a structure... No reason to dereference pstate.Sorry that I don't quite understand. We do need deference pstate to get the member base which has type
nouveau_cstate, and then assign the address of base to cstate for later use.
Quoted 7 lines
struct nouveau_pstate {
struct list_head head;
struct list_head list; /* c-states */
struct nouveau_cstate base;
u8 pstate;
u8 fanspeed;
};&pstate->base is the same thing as
(void *)pstate + offsetof(struct nouveau_pstate, base)
At no point is pstate dereferenced. In fact, take a look at
http://en.wikipedia.org/wiki/Offsetof
which says that the traditional implementation of offsetof is
#define offsetof(st, m) ((size_t)(&((st *)0)->m))
Cheers,
-ilia
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 48 lines · Ilia Mirkin
Quoted 36 lines · Vince Hsu
Quoted 25 lines · Ilia Mirkin
Quoted 24 lines · Vince Hsu
Quoted 23 lines · Ilia Mirkin
Quoted 14 lines · Andy Shevchenko
We have to check pointer before usage.
Reported-by Andrey Karpov <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/gpu/drm/nouveau/core/subdev/clock/base.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/nouveau/core/subdev/clock/base.c +0
-0drivers/gpu/drm/nouveau/core/subdev/clock/base.c nouveau_pstate_new(struct nouveau_clock *clk, int · line 326
Quoted 5 lines
drivers/gpu/drm/nouveau/core/subdev/clock/base.c +0
-1@@ -322,7 +322,6 @@ nouveau_pstate_new(struct nouveau_clock *clk, int idx)return 0 ; pstate =kzalloc (sizeof (*pstate),GFP_KERNEL ); - cstate = &pstate->base;What's wrong with this line? If pstate == NULL,
&pstate->base== NULL as well and we return.Quoted 6 lines
Quoted 3 lines
If pstate == NULL (kzalloc returned NULL),
pstate->basetriggers a null pointer
deference error?Where do you see "
pstate->base"? I only see "&pstate->base" which merely computes an offset into a structure... No reason to dereference pstate.Sorry that I don't quite understand. We do need deference pstate to get the member base which has type
nouveau_cstate, and then assign the address of base to cstate for later use.Quoted 7 lines
struct nouveau_pstate { struct list_head head; struct list_head list; /* c-states */ struct nouveau_cstate base; u8 pstate; u8 fanspeed; };
&pstate->baseis the same thing as(void *)pstate +
offsetof(struct nouveau_pstate, base)
Quoted 8 lines
At no point is pstate dereferenced. In fact, take a look at
http://en.wikipedia.org/wiki/Offsetof
which says that the traditional implementation of offsetof is
#define
offsetof(st, m)((size_t)(&((st *)0)->m))
Oh I got your point. You're absolutely right. Thanks for the patience. :)
Vince
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel