Skip to contentSkip to conversation

gpu/drm/drm_framebuffer.c: Add judgement for return value of drm_get_format_info().

PATCH In review Peng Hao 2 participants 4 messages Oct 27, 2023 – Oct 30, 2023

Subsystems (2)
lore
Share & tools
lore

Peng Hao

author
#0 lore raw

PATCH 1/1 gpu/drm/drm_framebuffer.c: Add judgement for return value of drm_get_format_info().

Since drm_get_format_info() may return NULL, so a judgement of return value is needed to add.

---
 drivers/gpu/drm/drm_framebuffer.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/drm_framebuffer.c +4 -0
index aff3746dedfb..be7dd1998c04 100644
@@ -194,6 +194,10 @@ static int framebuffer_check(struct drm_device *dev,
 
 	/* now let the driver pick its own format info */
 	info = drm_get_format_info(dev, r);
+	if (!info) {
+		drm_dbg_kms(dev, "no matched format info\n");
+		return -EFAULT;
+	}
 
 	for (i = 0; i < info->num_planes; i++) {
 		unsigned int width = fb_plane_width(r->width, info, i);
Signature · 1 line
2.37.1
#1 lore raw
Quoted 1 line · Peng Hao

Since drm_get_format_info() may return NULL,

Not in this case since we already checked it earlier.

Quoted 25 lines

so a judgement of return
value is needed to add.

---
 drivers/gpu/drm/drm_framebuffer.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/drm_framebuffer.c +4 -0
index aff3746dedfb..be7dd1998c04 100644
@@ -194,6 +194,10 @@ static int framebuffer_check(struct drm_device *dev,
 
 	/* now let the driver pick its own format info */
 	info = drm_get_format_info(dev, r);
+	if (!info) {
+		drm_dbg_kms(dev, "no matched format info\n");
+		return -EFAULT;
+	}
 
 	for (i = 0; i < info->num_planes; i++) {
 		unsigned int width = fb_plane_width(r->width, info, i);
Signature · 1 line
2.37.1
Signature · 2 lines
Ville Syrjälä
Intel
author
#2 lore raw

Hi, Ville & all
Thanks for quick reply!
According to your reply, the *info has been checked info earlier, and I have read the code of framebuffer_check() and related drm_get_format_info() which it calls, but unfortunatelly, I haven't seen  judgement(check) for it. What I only found related with check is the sentence below (in *drm_format_info() in drivers/gpu/drm/drm_fourcc.c):

```
info = __drm_format_info(format);
WARN_ON(!info);
``` 
But to the best of my knowledge, "WARN_ON" only gives a dump_stack(), not  discontinue the program going on, so it will indeed go to the below line in framebuffer_check() and raise an error:
```
for (i = 0; i < info->num_planes; i++) {
```

So maybe it will make  sense of my commited code.

Looking forward to your reply and guidance.

Quoted 39 lines
From: "Ville Syrjälä"<[email protected]>
Date:  Fri, Oct 27, 2023, 20:33
Subject:  Re: [PATCH] gpu/drm/drm_framebuffer.c: Add judgement for return value of drm_get_format_info().
To: "Peng Hao"<[email protected]>

Cc: <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>

Quoted 1 line · Peng Hao

Since drm_get_format_info() may return NULL,

Not in this case since we already checked it earlier.

Quoted 25 lines

so a judgement of return
value is needed to add.

---
 drivers/gpu/drm/drm_framebuffer.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/drm_framebuffer.c +4 -0
index aff3746dedfb..be7dd1998c04 100644
@@ -194,6 +194,10 @@ static int framebuffer_check(struct drm_device *dev,
 
 	/* now let the driver pick its own format info */
 	info = drm_get_format_info(dev, r);
+	if (!info) {
+		drm_dbg_kms(dev, "no matched format info\n");
+		return -EFAULT;
+	}
 
 	for (i = 0; i < info->num_planes; i++) {
 		unsigned int width = fb_plane_width(r->width, info, i);
Signature · 1 line
2.37.1
Signature · 2 lines
Ville Syrjälä
Intel
author
#3 lore raw
In reply to Ville Syrjälä

Hi, Ville & all
Thanks for quick reply!
According to your reply, the *info has been checked info earlier, and I have read the code of framebuffer_check() and related drm_get_format_info() which it calls, but unfortunatelly, I haven't seen  judgement(check) for it. What I only found related with check is the sentence below (in *drm_format_info() in drivers/gpu/drm/drm_fourcc.c):

```
info = __drm_format_info(format);
WARN_ON(!info);
``` 
But to the best of my knowledge, "WARN_ON" only gives a dump_stack(), not  discontinue the program going on, so it will indeed go to the below line in framebuffer_check() and raise an error:
```
for (i = 0; i < info->num_planes; i++) {
```

So maybe it will make  sense of my commited code.

Looking forward to your reply and guidance.

Quoted 39 lines
From: "Ville Syrjälä"<[email protected]>
Date:  Fri, Oct 27, 2023, 20:33
Subject:  Re: [PATCH] gpu/drm/drm_framebuffer.c: Add judgement for return value of drm_get_format_info().
To: "Peng Hao"<[email protected]>

Cc: <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>

Quoted 1 line · Peng Hao

Since drm_get_format_info() may return NULL,

Not in this case since we already checked it earlier.

Quoted 25 lines

so a judgement of return
value is needed to add.

---
 drivers/gpu/drm/drm_framebuffer.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/drm_framebuffer.c +4 -0
index aff3746dedfb..be7dd1998c04 100644
@@ -194,6 +194,10 @@ static int framebuffer_check(struct drm_device *dev,
 
 	/* now let the driver pick its own format info */
 	info = drm_get_format_info(dev, r);
+	if (!info) {
+		drm_dbg_kms(dev, "no matched format info\n");
+		return -EFAULT;
+	}
 
 	for (i = 0; i < info->num_planes; i++) {
 		unsigned int width = fb_plane_width(r->width, info, i);
Signature · 1 line
2.37.1
Signature · 2 lines
Ville Syrjälä
Intel