public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] uvc: kmalloc failure ignored in uvc_ctrl_add_ctrl()
@ 2009-09-19  1:13 Roel Kluin
  2009-09-24  6:20 ` Laurent Pinchart
  0 siblings, 1 reply; 4+ messages in thread
From: Roel Kluin @ 2009-09-19  1:13 UTC (permalink / raw)
  To: Laurent Pinchart, linux-uvc-devel, linux-media, Andrew Morton

Produce an error if kmalloc() fails.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
Found with sed: http://kernelnewbies.org/roelkluin

Build tested. Please review

diff --git a/drivers/media/video/uvc/uvc_ctrl.c b/drivers/media/video/uvc/uvc_ctrl.c
index c3225a5..dda80b5 100644
--- a/drivers/media/video/uvc/uvc_ctrl.c
+++ b/drivers/media/video/uvc/uvc_ctrl.c
@@ -1189,7 +1189,7 @@ int uvc_ctrl_resume_device(struct uvc_device *dev)
  * Control and mapping handling
  */
 
-static void uvc_ctrl_add_ctrl(struct uvc_device *dev,
+static int uvc_ctrl_add_ctrl(struct uvc_device *dev,
 	struct uvc_control_info *info)
 {
 	struct uvc_entity *entity;
@@ -1214,7 +1214,7 @@ static void uvc_ctrl_add_ctrl(struct uvc_device *dev,
 	}
 
 	if (!found)
-		return;
+		return 0;
 
 	if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT) {
 		/* Check if the device control information and length match
@@ -1231,7 +1231,7 @@ static void uvc_ctrl_add_ctrl(struct uvc_device *dev,
 				"control " UVC_GUID_FORMAT "/%u (%d).\n",
 				UVC_GUID_ARGS(info->entity), info->selector,
 				ret);
-			return;
+			return -EINVAL;
 		}
 
 		if (info->size != le16_to_cpu(size)) {
@@ -1239,7 +1239,7 @@ static void uvc_ctrl_add_ctrl(struct uvc_device *dev,
 				"/%u size doesn't match user supplied "
 				"value.\n", UVC_GUID_ARGS(info->entity),
 				info->selector);
-			return;
+			return -EINVAL;
 		}
 
 		ret = uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id,
@@ -1249,7 +1249,7 @@ static void uvc_ctrl_add_ctrl(struct uvc_device *dev,
 				"control " UVC_GUID_FORMAT "/%u (%d).\n",
 				UVC_GUID_ARGS(info->entity), info->selector,
 				ret);
-			return;
+			return -EINVAL;
 		}
 
 		flags = info->flags;
@@ -1259,15 +1259,18 @@ static void uvc_ctrl_add_ctrl(struct uvc_device *dev,
 				UVC_GUID_FORMAT "/%u flags don't match "
 				"supported operations.\n",
 				UVC_GUID_ARGS(info->entity), info->selector);
-			return;
+			return -EINVAL;
 		}
 	}
 
 	ctrl->info = info;
 	ctrl->data = kmalloc(ctrl->info->size * UVC_CTRL_NDATA, GFP_KERNEL);
+	if (ctrl->data == NULL)
+		return -ENOMEM;
 	uvc_trace(UVC_TRACE_CONTROL, "Added control " UVC_GUID_FORMAT "/%u "
 		"to device %s entity %u\n", UVC_GUID_ARGS(ctrl->info->entity),
 		ctrl->info->selector, dev->udev->devpath, entity->id);
+	return 0;
 }
 
 /*
@@ -1309,8 +1312,11 @@ int uvc_ctrl_add_info(struct uvc_control_info *info)
 		}
 	}
 
-	list_for_each_entry(dev, &uvc_driver.devices, list)
-		uvc_ctrl_add_ctrl(dev, info);
+	list_for_each_entry(dev, &uvc_driver.devices, list) {
+		ret = uvc_ctrl_add_ctrl(dev, info);
+		if (ret == -ENOMEM)
+			goto end;
+	}
 
 	INIT_LIST_HEAD(&info->mappings);
 	list_add_tail(&info->list, &uvc_driver.controls);

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

end of thread, other threads:[~2009-09-24 21:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-19  1:13 [PATCH] uvc: kmalloc failure ignored in uvc_ctrl_add_ctrl() Roel Kluin
2009-09-24  6:20 ` Laurent Pinchart
2009-09-24  8:50   ` [Linux-uvc-devel] " Paulo Assis
2009-09-24 21:06     ` Laurent Pinchart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox