All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/msm/adreno/a5xx_debugfs: fix potential NULL pointer dereference
@ 2018-02-02 12:32 Gustavo A. R. Silva
  2018-02-02 16:30   ` Jordan Crouse
  0 siblings, 1 reply; 7+ messages in thread
From: Gustavo A. R. Silva @ 2018-02-02 12:32 UTC (permalink / raw)
  To: Rob Clark, David Airlie
  Cc: linux-arm-msm, dri-devel, freedreno, linux-kernel,
	Gustavo A. R. Silva

_minor_ is being dereferenced before it is null checked, hence there
is a potential null pointer dereference. Fix this by moving the pointer
dereference after _minor_ has been null checked.

Fixes: 024ad8df763f ("drm/msm: add a5xx specific debugfs")
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---

I wonder if a better solution for this would be to WARN_ON in case _minor_
happens to be NULL and return -EINVAL, instead of just returning zero.

Something like:

struct drm_device *dev;

if (WARN_ON(!minor)
	return -EINVAL;

dev = minor->dev;

What do you think?

Thanks


 drivers/gpu/drm/msm/adreno/a5xx_debugfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/msm/adreno/a5xx_debugfs.c b/drivers/gpu/drm/msm/adreno/a5xx_debugfs.c
index 6b27941..059ec7d 100644
--- a/drivers/gpu/drm/msm/adreno/a5xx_debugfs.c
+++ b/drivers/gpu/drm/msm/adreno/a5xx_debugfs.c
@@ -159,13 +159,15 @@ DEFINE_SIMPLE_ATTRIBUTE(reset_fops, NULL, reset_set, "%llx\n");
 
 int a5xx_debugfs_init(struct msm_gpu *gpu, struct drm_minor *minor)
 {
-	struct drm_device *dev = minor->dev;
+	struct drm_device *dev;
 	struct dentry *ent;
 	int ret;
 
 	if (!minor)
 		return 0;
 
+	dev = minor->dev;
+
 	ret = drm_debugfs_create_files(a5xx_debugfs_list,
 			ARRAY_SIZE(a5xx_debugfs_list),
 			minor->debugfs_root, minor);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-02-03 12:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-02 12:32 [PATCH] drm/msm/adreno/a5xx_debugfs: fix potential NULL pointer dereference Gustavo A. R. Silva
2018-02-02 16:30 ` Jordan Crouse
2018-02-02 16:30   ` Jordan Crouse
     [not found]   ` <20180202163006.GA878-9PYrDHPZ2Orvke4nUoYGnHL1okKdlPRT@public.gmane.org>
2018-02-02 19:04     ` Rob Clark
2018-02-02 19:04       ` Rob Clark
     [not found]       ` <CAF6AEGuKHknW3o4tfe95E7RLLk7OQGTFh=HDtijPDQyp3b+B6Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-02-03 12:22         ` Gustavo A. R. Silva
2018-02-03 12:22           ` Gustavo A. R. Silva

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.