All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roel Kluin <roel.kluin@gmail.com>
To: Laurent Pinchart <laurent.pinchart@skynet.be>,
	linux-uvc-devel@lists.berlios.de, linux-media@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH] uvc: kmalloc failure ignored in uvc_ctrl_add_ctrl()
Date: Sat, 19 Sep 2009 03:13:37 +0200	[thread overview]
Message-ID: <4AB43041.6050001@gmail.com> (raw)

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

             reply	other threads:[~2009-09-19  1:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-19  1:13 Roel Kluin [this message]
2009-09-24  6:20 ` [PATCH] uvc: kmalloc failure ignored in uvc_ctrl_add_ctrl() Laurent Pinchart
2009-09-24  8:50   ` [Linux-uvc-devel] " Paulo Assis
2009-09-24 21:06     ` Laurent Pinchart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4AB43041.6050001@gmail.com \
    --to=roel.kluin@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=laurent.pinchart@skynet.be \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-uvc-devel@lists.berlios.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.