Skip to contentSkip to conversation

drm/drm_ioctl.c: Test client capability value early when setting.

PATCH In review Liviu Dudau 3 participants 6 messages Feb 28, 2018 – Mar 6, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/drm_ioctl.c: Test client capability value early when setting.

The drm_setclientcap() function implementing the DRM_IOCTL_SET_CLIENT_CAP ioctl expects that any capability set by the client will have a value of 1. Make the check early so that we don't have to test the value for each capability.

---
 drivers/gpu/drm/drm_ioctl.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_ioctl.c +3 -6
index af782911c505..02ffa0e8d77b 100644
@@ -306,22 +306,19 @@ drm_setclientcap(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
 	struct drm_set_client_cap *req = data;
 
+	if (req->value > 1)
+		return -EINVAL;
+
 	switch (req->capability) {
 	case DRM_CLIENT_CAP_STEREO_3D:
-		if (req->value > 1)
-			return -EINVAL;
 		file_priv->stereo_allowed = req->value;
 		break;
 	case DRM_CLIENT_CAP_UNIVERSAL_PLANES:
-		if (req->value > 1)
-			return -EINVAL;
 		file_priv->universal_planes = req->value;
 		break;
 	case DRM_CLIENT_CAP_ATOMIC:
 		if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
 			return -EINVAL;
-		if (req->value > 1)
-			return -EINVAL;
 		file_priv->atomic = req->value;
 		file_priv->universal_planes = req->value;
 		break;
Signature · 6 lines
2.16.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 4 lines · Liviu Dudau

The drm_setclientcap() function implementing the DRM_IOCTL_SET_CLIENT_CAP ioctl expects that any capability set by the client will have a value of 1. Make the check early so that we don't have to test the value for each capability.

What if we want a a non-boolean capability at some point?

Quoted 43 lines
---
 drivers/gpu/drm/drm_ioctl.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_ioctl.c +3 -6
index af782911c505..02ffa0e8d77b 100644
@@ -306,22 +306,19 @@ drm_setclientcap(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
 	struct drm_set_client_cap *req = data;
 
+	if (req->value > 1)
+		return -EINVAL;
+
 	switch (req->capability) {
 	case DRM_CLIENT_CAP_STEREO_3D:
-		if (req->value > 1)
-			return -EINVAL;
 		file_priv->stereo_allowed = req->value;
 		break;
 	case DRM_CLIENT_CAP_UNIVERSAL_PLANES:
-		if (req->value > 1)
-			return -EINVAL;
 		file_priv->universal_planes = req->value;
 		break;
 	case DRM_CLIENT_CAP_ATOMIC:
 		if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
 			return -EINVAL;
-		if (req->value > 1)
-			return -EINVAL;
 		file_priv->atomic = req->value;
 		file_priv->universal_planes = req->value;
 		break;
Signature · 6 lines
2.16.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw
Quoted 7 lines · Ville Syrjälä
Quoted 4 lines · Liviu Dudau

The drm_setclientcap() function implementing the DRM_IOCTL_SET_CLIENT_CAP ioctl expects that any capability set by the client will have a value of 1. Make the check early so that we don't have to test the value for each capability.

What if we want a a non-boolean capability at some point?

Well, I'm adding another boolean capability soon, so you will be going against the trend :)

I guess you will have 2 options: revert the patch or add a condition to the test.

I don't have strong feelings, just felt like too much copying when adding another capability so I thought to do some "cleanup".

Best regards,
Liviu

Quoted 48 lines
Quoted 44 lines
---
 drivers/gpu/drm/drm_ioctl.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_ioctl.c +3 -6
index af782911c505..02ffa0e8d77b 100644
@@ -306,22 +306,19 @@ drm_setclientcap(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
 	struct drm_set_client_cap *req = data;
 
+	if (req->value > 1)
+		return -EINVAL;
+
 	switch (req->capability) {
 	case DRM_CLIENT_CAP_STEREO_3D:
-		if (req->value > 1)
-			return -EINVAL;
 		file_priv->stereo_allowed = req->value;
 		break;
 	case DRM_CLIENT_CAP_UNIVERSAL_PLANES:
-		if (req->value > 1)
-			return -EINVAL;
 		file_priv->universal_planes = req->value;
 		break;
 	case DRM_CLIENT_CAP_ATOMIC:
 		if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
 			return -EINVAL;
-		if (req->value > 1)
-			return -EINVAL;
 		file_priv->atomic = req->value;
 		file_priv->universal_planes = req->value;
 		break;
Signature · 6 lines
2.16.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 2 lines
Ville Syrjälä
Intel OTC
Signature · 12 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw
Quoted 11 lines · Liviu Dudau
Quoted 7 lines · Ville Syrjälä
Quoted 4 lines · Liviu Dudau

The drm_setclientcap() function implementing the DRM_IOCTL_SET_CLIENT_CAP ioctl expects that any capability set by the client will have a value of 1. Make the check early so that we don't have to test the value for each capability.

What if we want a a non-boolean capability at some point?

Well, I'm adding another boolean capability soon, so you will be going against the trend :)

Plenty of non-bools in driver specific counterparts I believe.

Quoted 67 lines

I guess you will have 2 options: revert the patch or add a condition to the test.

I don't have strong feelings, just felt like too much copying when adding another capability so I thought to do some "cleanup".

Best regards,
Liviu

Quoted 48 lines
Quoted 44 lines
---
 drivers/gpu/drm/drm_ioctl.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_ioctl.c +3 -6
index af782911c505..02ffa0e8d77b 100644
@@ -306,22 +306,19 @@ drm_setclientcap(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
 	struct drm_set_client_cap *req = data;
 
+	if (req->value > 1)
+		return -EINVAL;
+
 	switch (req->capability) {
 	case DRM_CLIENT_CAP_STEREO_3D:
-		if (req->value > 1)
-			return -EINVAL;
 		file_priv->stereo_allowed = req->value;
 		break;
 	case DRM_CLIENT_CAP_UNIVERSAL_PLANES:
-		if (req->value > 1)
-			return -EINVAL;
 		file_priv->universal_planes = req->value;
 		break;
 	case DRM_CLIENT_CAP_ATOMIC:
 		if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
 			return -EINVAL;
-		if (req->value > 1)
-			return -EINVAL;
 		file_priv->atomic = req->value;
 		file_priv->universal_planes = req->value;
 		break;
Signature · 6 lines
2.16.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 2 lines
Ville Syrjälä
Intel OTC
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw
Quoted 8 lines · Ville Syrjälä
Quoted 7 lines · Liviu Dudau
Quoted 6 lines · Ville Syrjälä
Quoted 4 lines · Liviu Dudau

The drm_setclientcap() function implementing the DRM_IOCTL_SET_CLIENT_CAP ioctl expects that any capability set by the client will have a value of 1. Make the check early so that we don't have to test the value for each capability.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

What if we want a a non-boolean capability at some point?

Well, I'm adding another boolean capability soon, so you will be going against the trend :)

Plenty of non-bools in driver specific counterparts I believe.

So, is that a NACK?

Quoted 72 lines
Quoted 68 lines

I guess you will have 2 options: revert the patch or add a condition to the test.

I don't have strong feelings, just felt like too much copying when adding another capability so I thought to do some "cleanup".

Best regards,
Liviu

Quoted 48 lines
Quoted 44 lines
---
 drivers/gpu/drm/drm_ioctl.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_ioctl.c +3 -6
index af782911c505..02ffa0e8d77b 100644
@@ -306,22 +306,19 @@ drm_setclientcap(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
 	struct drm_set_client_cap *req = data;
 
+	if (req->value > 1)
+		return -EINVAL;
+
 	switch (req->capability) {
 	case DRM_CLIENT_CAP_STEREO_3D:
-		if (req->value > 1)
-			return -EINVAL;
 		file_priv->stereo_allowed = req->value;
 		break;
 	case DRM_CLIENT_CAP_UNIVERSAL_PLANES:
-		if (req->value > 1)
-			return -EINVAL;
 		file_priv->universal_planes = req->value;
 		break;
 	case DRM_CLIENT_CAP_ATOMIC:
 		if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
 			return -EINVAL;
-		if (req->value > 1)
-			return -EINVAL;
 		file_priv->atomic = req->value;
 		file_priv->universal_planes = req->value;
 		break;
Signature · 6 lines
2.16.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 2 lines
Ville Syrjälä
Intel OTC
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
Signature · 2 lines
Ville Syrjälä
Intel OTC
Signature · 12 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw
Quoted 9 lines · Liviu Dudau
Quoted 8 lines · Ville Syrjälä
Quoted 7 lines · Liviu Dudau
Quoted 6 lines · Ville Syrjälä
Quoted 4 lines · Liviu Dudau

The drm_setclientcap() function implementing the DRM_IOCTL_SET_CLIENT_CAP ioctl expects that any capability set by the client will have a value of 1. Make the check early so that we don't have to test the value for each capability.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

What if we want a a non-boolean capability at some point?

Well, I'm adding another boolean capability soon, so you will be going against the trend :)

Plenty of non-bools in driver specific counterparts I believe.

So, is that a NACK?

Yeah I think this is overoptimizing for not repeating code. -Daniel

Quoted 84 lines
Quoted 74 lines
Quoted 70 lines

I guess you will have 2 options: revert the patch or add a condition to the test.

I don't have strong feelings, just felt like too much copying when adding another capability so I thought to do some "cleanup".

Best regards,
Liviu

Quoted 48 lines
Quoted 44 lines
---
 drivers/gpu/drm/drm_ioctl.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_ioctl.c +3 -6
index af782911c505..02ffa0e8d77b 100644
@@ -306,22 +306,19 @@ drm_setclientcap(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
 	struct drm_set_client_cap *req = data;
 
+	if (req->value > 1)
+		return -EINVAL;
+
 	switch (req->capability) {
 	case DRM_CLIENT_CAP_STEREO_3D:
-		if (req->value > 1)
-			return -EINVAL;
 		file_priv->stereo_allowed = req->value;
 		break;
 	case DRM_CLIENT_CAP_UNIVERSAL_PLANES:
-		if (req->value > 1)
-			return -EINVAL;
 		file_priv->universal_planes = req->value;
 		break;
 	case DRM_CLIENT_CAP_ATOMIC:
 		if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
 			return -EINVAL;
-		if (req->value > 1)
-			return -EINVAL;
 		file_priv->atomic = req->value;
 		file_priv->universal_planes = req->value;
 		break;
Signature · 6 lines
2.16.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 2 lines
Ville Syrjälä
Intel OTC
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
Signature · 2 lines
Ville Syrjälä
Intel OTC
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel