From patchwork Sun Mar 21 21:31:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 2991 Return-path: Envelope-to: mchehab@infradead.org Delivery-date: Sun, 21 Mar 2010 21:31:51 +0000 Received: from bombadil.infradead.org [18.85.46.34] by pedra with IMAP (fetchmail-6.3.6) for (single-drop); Sun, 21 Mar 2010 18:35:07 -0300 (BRT) Received: from vger.kernel.org ([209.132.180.67]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NtSkR-0007oU-7u; Sun, 21 Mar 2010 21:31:51 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753744Ab0CUVbK (ORCPT + 1 other); Sun, 21 Mar 2010 17:31:10 -0400 Received: from mgw2.diku.dk ([130.225.96.92]:41002 "EHLO mgw2.diku.dk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753612Ab0CUVbI (ORCPT ); Sun, 21 Mar 2010 17:31:08 -0400 Received: from localhost (localhost [127.0.0.1]) by mgw2.diku.dk (Postfix) with ESMTP id BF22819BCBA; Sun, 21 Mar 2010 22:31:07 +0100 (CET) Received: from mgw2.diku.dk ([127.0.0.1]) by localhost (mgw2.diku.dk [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 27517-17; Sun, 21 Mar 2010 22:31:06 +0100 (CET) Received: from nhugin.diku.dk (nhugin.diku.dk [130.225.96.140]) by mgw2.diku.dk (Postfix) with ESMTP id 87B6819BCB8; Sun, 21 Mar 2010 22:31:06 +0100 (CET) Received: from ask.diku.dk (ask.diku.dk [130.225.96.225]) by nhugin.diku.dk (Postfix) with ESMTP id 16E6D6DFB75; Sun, 21 Mar 2010 22:25:07 +0100 (CET) Received: by ask.diku.dk (Postfix, from userid 3767) id 6BA9B200B0; Sun, 21 Mar 2010 22:31:06 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by ask.diku.dk (Postfix) with ESMTP id 5E94A200AF; Sun, 21 Mar 2010 22:31:06 +0100 (CET) Date: Sun, 21 Mar 2010 22:31:06 +0100 (CET) From: Julia Lawall To: Mark McClelland , Mauro Carvalho Chehab , linux-usb@vger.kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] drivers/media/video: avoid NULL dereference Message-ID: MIME-Version: 1.0 X-Virus-Scanned: amavisd-new at diku.dk Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Julia Lawall If ov is NULL, it will not be possible to take the lock in the first place, so move the test up earlier. The semantic match that finds the problem is as follows: (http://coccinelle.lip6.fr/) // @r exists@ expression E, E1; identifier f; statement S1,S3; iterator iter; @@ if ((E == NULL && ...) || ...) { ... when != false ((E == NULL && ...) || ...) when != true ((E != NULL && ...) || ...) when != iter(E,...) S1 when != E = E1 ( sizeof(E->f) | * E->f ) ... when any return ...; } else S3 // Signed-off-by: Julia Lawall --- drivers/media/video/ov511.c | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/media/video/ov511.c b/drivers/media/video/ov511.c index e0bce8d..2357218 100644 --- a/drivers/media/video/ov511.c +++ b/drivers/media/video/ov511.c @@ -5913,14 +5913,12 @@ ov51x_disconnect(struct usb_interface *intf) PDEBUG(3, ""); + if (!ov) + return; + mutex_lock(&ov->lock); usb_set_intfdata (intf, NULL); - if (!ov) { - mutex_unlock(&ov->lock); - return; - } - /* Free device number */ ov511_devused &= ~(1 << ov->nr);