diff mbox

drm_crtc: add kmalloc NULL handling

Message ID 4d4f050f.cb05df0a.4fb8.4e47@mx.google.com (mailing list archive)
State New, archived
Headers show

Commit Message

Stanislav Fomichev Feb. 6, 2011, 8:31 p.m. UTC
None
diff mbox

Patch

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);