[PATCH] drm_crtc: add kmalloc NULL handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Exit from drm_mode_create_tv_properties and
drm_mode_connector_update_edid_property with -ENOMEM if some of the
internal allocations fails.

This patch fixes only the mentioned routines but doesn't add handling of
the returned values to the caller side. If this patch will be accepted,
I'll also try to add error handling to the callers of this functions.

Compile tested only.

Signed-off-by: Stanislav Fomichev <kernel@xxxxxxxxxxx>
---
 drivers/gpu/drm/drm_crtc.c |  158 ++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 147 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 654faa8..10485da 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -657,6 +657,7 @@ int drm_mode_create_tv_properties(struct drm_device *dev, int num_modes,
 	struct drm_property *tv_selector;
 	struct drm_property *tv_subconnector;
 	int i;
+	int err;
 
 	if (dev->mode_config.tv_select_subconnector_property)
 		return 0;
@@ -667,20 +668,39 @@ int drm_mode_create_tv_properties(struct drm_device *dev, int num_modes,
 	tv_selector = drm_property_create(dev, DRM_MODE_PROP_ENUM,
 					  "select subconnector",
 					  ARRAY_SIZE(drm_tv_select_enum_list));
-	for (i = 0; i < ARRAY_SIZE(drm_tv_select_enum_list); i++)
-		drm_property_add_enum(tv_selector, i,
-				      drm_tv_select_enum_list[i].type,
-				      drm_tv_select_enum_list[i].name);
+
+	if (!tv_selector)
+		return -ENOMEM;
+
+	for (i = 0; i < ARRAY_SIZE(drm_tv_select_enum_list); i++) {
+		err = drm_property_add_enum(tv_selector, i,
+					    drm_tv_select_enum_list[i].type,
+					    drm_tv_select_enum_list[i].name);
+
+		if (err)
+			goto destroy_tv_selector;
+	}
+
 	dev->mode_config.tv_select_subconnector_property = tv_selector;
 
 	tv_subconnector =
 		drm_property_create(dev, DRM_MODE_PROP_ENUM |
 				    DRM_MODE_PROP_IMMUTABLE, "subconnector",
 				    ARRAY_SIZE(drm_tv_subconnector_enum_list));
-	for (i = 0; i < ARRAY_SIZE(drm_tv_subconnector_enum_list); i++)
-		drm_property_add_enum(tv_subconnector, i,
-				      drm_tv_subconnector_enum_list[i].type,
-				      drm_tv_subconnector_enum_list[i].name);
+
+	if (!tv_subconnector) {
+		err = -ENOMEM;
+		goto destroy_tv_selector;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(drm_tv_subconnector_enum_list); i++) {
+		err = drm_property_add_enum(tv_subconnector, i,
+					    drm_tv_subconnector_enum_list[i].type,
+					    drm_tv_subconnector_enum_list[i].name);
+
+		if (err)
+			goto destroy_tv_subconnector;
+	}
 	dev->mode_config.tv_subconnector_property = tv_subconnector;
 
 	/*
@@ -689,71 +709,184 @@ int drm_mode_create_tv_properties(struct drm_device *dev, int num_modes,
 	dev->mode_config.tv_left_margin_property =
 		drm_property_create(dev, DRM_MODE_PROP_RANGE,
 				    "left margin", 2);
+
+	if (!dev->mode_config.tv_left_margin_property) {
+		err = -ENOMEM;
+		goto destroy_tv_subconnector;
+	}
+
 	dev->mode_config.tv_left_margin_property->values[0] = 0;
 	dev->mode_config.tv_left_margin_property->values[1] = 100;
 
 	dev->mode_config.tv_right_margin_property =
 		drm_property_create(dev, DRM_MODE_PROP_RANGE,
 				    "right margin", 2);
+
+	if (!dev->mode_config.tv_right_margin_property) {
+		err = -ENOMEM;
+		goto destroy_tv_left_margin;
+	}
 	dev->mode_config.tv_right_margin_property->values[0] = 0;
 	dev->mode_config.tv_right_margin_property->values[1] = 100;
 
 	dev->mode_config.tv_top_margin_property =
 		drm_property_create(dev, DRM_MODE_PROP_RANGE,
 				    "top margin", 2);
+
+	if (!dev->mode_config.tv_top_margin_property) {
+		err = -ENOMEM;
+		goto destroy_tv_right_margin;
+	}
+
 	dev->mode_config.tv_top_margin_property->values[0] = 0;
 	dev->mode_config.tv_top_margin_property->values[1] = 100;
 
 	dev->mode_config.tv_bottom_margin_property =
 		drm_property_create(dev, DRM_MODE_PROP_RANGE,
 				    "bottom margin", 2);
+
+	if (!dev->mode_config.tv_bottom_margin_property) {
+		err = -ENOMEM;
+		goto destroy_tv_top_margin;
+	}
+
 	dev->mode_config.tv_bottom_margin_property->values[0] = 0;
 	dev->mode_config.tv_bottom_margin_property->values[1] = 100;
 
 	dev->mode_config.tv_mode_property =
 		drm_property_create(dev, DRM_MODE_PROP_ENUM,
 				    "mode", num_modes);
-	for (i = 0; i < num_modes; i++)
-		drm_property_add_enum(dev->mode_config.tv_mode_property, i,
-				      i, modes[i]);
+
+	if (!dev->mode_config.tv_mode_property) {
+		err = -ENOMEM;
+		goto destroy_tv_bottom_margin;
+	}
+
+	for (i = 0; i < num_modes; i++) {
+		err = drm_property_add_enum(dev->mode_config.tv_mode_property,
+					    i, i, modes[i]);
+
+		if (err)
+			goto destroy_tv_mode;
+	}
 
 	dev->mode_config.tv_brightness_property =
 		drm_property_create(dev, DRM_MODE_PROP_RANGE,
 				    "brightness", 2);
+
+	if (!dev->mode_config.tv_brightness_property) {
+		err = -ENOMEM;
+
+		goto destroy_tv_mode;
+	}
+
 	dev->mode_config.tv_brightness_property->values[0] = 0;
 	dev->mode_config.tv_brightness_property->values[1] = 100;
 
 	dev->mode_config.tv_contrast_property =
 		drm_property_create(dev, DRM_MODE_PROP_RANGE,
 				    "contrast", 2);
+
+	if (!dev->mode_config.tv_contrast_property) {
+		err = -ENOMEM;
+
+		goto destroy_tv_brightness;
+	}
+
 	dev->mode_config.tv_contrast_property->values[0] = 0;
 	dev->mode_config.tv_contrast_property->values[1] = 100;
 
 	dev->mode_config.tv_flicker_reduction_property =
 		drm_property_create(dev, DRM_MODE_PROP_RANGE,
 				    "flicker reduction", 2);
+
+	if (!dev->mode_config.tv_flicker_reduction_property) {
+		err = -ENOMEM;
+
+		goto destroy_tv_contrast;
+	}
+
 	dev->mode_config.tv_flicker_reduction_property->values[0] = 0;
 	dev->mode_config.tv_flicker_reduction_property->values[1] = 100;
 
 	dev->mode_config.tv_overscan_property =
 		drm_property_create(dev, DRM_MODE_PROP_RANGE,
 				    "overscan", 2);
+
+	if (!dev->mode_config.tv_overscan_property) {
+		err = -ENOMEM;
+
+		goto destroy_tv_flicker_reduction;
+	}
+
 	dev->mode_config.tv_overscan_property->values[0] = 0;
 	dev->mode_config.tv_overscan_property->values[1] = 100;
 
 	dev->mode_config.tv_saturation_property =
 		drm_property_create(dev, DRM_MODE_PROP_RANGE,
 				    "saturation", 2);
+
+	if (!dev->mode_config.tv_saturation_property) {
+		err = -ENOMEM;
+
+		goto destroy_tv_overscan;
+	}
+
 	dev->mode_config.tv_saturation_property->values[0] = 0;
 	dev->mode_config.tv_saturation_property->values[1] = 100;
 
 	dev->mode_config.tv_hue_property =
 		drm_property_create(dev, DRM_MODE_PROP_RANGE,
 				    "hue", 2);
+
+	if (!dev->mode_config.tv_hue_property) {
+		err = -ENOMEM;
+
+		goto destroy_tv_saturation;
+	}
+
 	dev->mode_config.tv_hue_property->values[0] = 0;
 	dev->mode_config.tv_hue_property->values[1] = 100;
 
 	return 0;
+
+destroy_tv_saturation:
+	drm_property_destroy(dev, dev->mode_config.tv_saturation_property);
+
+destroy_tv_overscan:
+	drm_property_destroy(dev, dev->mode_config.tv_overscan_property);
+
+destroy_tv_flicker_reduction:
+	drm_property_destroy(dev, dev->mode_config.tv_flicker_reduction_property);
+
+destroy_tv_contrast:
+	drm_property_destroy(dev, dev->mode_config.tv_contrast_property);
+
+destroy_tv_brightness:
+	drm_property_destroy(dev, dev->mode_config.tv_brightness_property);
+
+destroy_tv_mode:
+	drm_property_destroy(dev, dev->mode_config.tv_mode_property);
+
+destroy_tv_bottom_margin:
+	drm_property_destroy(dev, dev->mode_config.tv_bottom_margin_property);
+
+destroy_tv_top_margin:
+	drm_property_destroy(dev, dev->mode_config.tv_top_margin_property);
+
+destroy_tv_right_margin:
+	drm_property_destroy(dev, dev->mode_config.tv_right_margin_property);
+
+destroy_tv_left_margin:
+	drm_property_destroy(dev, dev->mode_config.tv_left_margin_property);
+
+destroy_tv_subconnector:
+	drm_property_destroy(dev, tv_subconnector);
+
+destroy_tv_selector:
+	drm_property_destroy(dev, tv_selector);
+
+	return err;
 }
 EXPORT_SYMBOL(drm_mode_create_tv_properties);
 
@@ -2375,6 +2508,9 @@ int drm_mode_connector_update_edid_property(struct drm_connector *connector,
 	connector->edid_blob_ptr = drm_property_create_blob(connector->dev,
 							    size, edid);
 
+	if (!connector->edid_blob_ptr)
+		return -ENOMEM;
+
 	ret = drm_connector_property_set_value(connector,
 					       dev->mode_config.edid_property,
 					       connector->edid_blob_ptr->base.id);
-- 
1.7.1
_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux