From patchwork Wed Jul 2 21:44:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rickard Strandqvist X-Patchwork-Id: 4468121 Return-Path: X-Original-To: patchwork-linux-fbdev@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E11B59F26C for ; Wed, 2 Jul 2014 21:43:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 19D0620384 for ; Wed, 2 Jul 2014 21:43:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 55EB4202E5 for ; Wed, 2 Jul 2014 21:43:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753512AbaGBVnw (ORCPT ); Wed, 2 Jul 2014 17:43:52 -0400 Received: from mail-wi0-f176.google.com ([209.85.212.176]:55025 "EHLO mail-wi0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753304AbaGBVnk (ORCPT ); Wed, 2 Jul 2014 17:43:40 -0400 Received: by mail-wi0-f176.google.com with SMTP id n3so10390096wiv.15 for ; Wed, 02 Jul 2014 14:43:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Z/SmjDvm/qWqKkDtR6uRG0a/TlFRfFD0NFKPFIrhkEQ=; b=k10tg0Zv/F+deOswDpM8jD1tV1hcsj1oIOhnSkalmrfmBpZsRCp1MJYuyuTIRKO+IZ L99+2om2YIQUl51UPCFOTi04PqMxM89Gtm/xKLMxn2wau7wckUrV8t9yj/D3EeW8jsWn mYwwzwCYYR2FPAInghHnp0avFdTSiDb4/sJBlcL4xZ4PuGB2k9zsVZ3Rrta3RaNzPC8h NAHD/RcL5gYSJPTbRxFwEmDPEef9b8iWD+byphvdwh1O66WlezKN2bCAraChNnkTWOKP KRGfFIUp21bn+EODc/eKOmer1EGlhXybiwkvx8Oxid6ylClsf6frrFg1AyIUif5R0X/o 9n0A== X-Gm-Message-State: ALoCoQm10z3yilYIn/1x+swjUeAN0rmEoRzVV+Iu8U4Y7wH1APOAIZ3yCc3V1Ah2cZLQWl4zLBgJ X-Received: by 10.180.37.180 with SMTP id z20mr6791413wij.58.1404337418134; Wed, 02 Jul 2014 14:43:38 -0700 (PDT) Received: from localhost.localdomain (h-245-62.a218.priv.bahnhof.se. [85.24.245.62]) by mx.google.com with ESMTPSA id o3sm59466290wix.15.2014.07.02.14.43.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Jul 2014 14:43:37 -0700 (PDT) From: Rickard Strandqvist To: Jean-Christophe Plagniol-Villard , Tomi Valkeinen Cc: Rickard Strandqvist , Jingoo Han , Daniel Vetter , Laurent Pinchart , Rob Clark , David Ung , linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] video: fbdev: core: fbmon.c: Fix for possible null pointer dereference Date: Wed, 2 Jul 2014 23:44:53 +0200 Message-Id: <1404337493-6416-1-git-send-email-rickard_strandqvist@spectrumdigital.se> X-Mailer: git-send-email 1.7.10.4 Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix a possible null pointer dereference, there is otherwise a risk of a possible null pointer dereference This was found using a static code analysis program called cppcheck Signed-off-by: Rickard Strandqvist --- drivers/video/fbdev/core/fbmon.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/video/fbdev/core/fbmon.c b/drivers/video/fbdev/core/fbmon.c index 5b0e313..9ec81ee 100644 --- a/drivers/video/fbdev/core/fbmon.c +++ b/drivers/video/fbdev/core/fbmon.c @@ -608,6 +608,11 @@ static struct fb_videomode *fb_create_modedb(unsigned char *edid, int *dbsize) int num = 0, i, first = 1; int ver, rev; + if (edid == NULL || !edid_checksum(edid) || + !edid_check_header(edid)) { + return NULL; + } + ver = edid[EDID_STRUCT_VERSION]; rev = edid[EDID_STRUCT_REVISION]; @@ -615,12 +620,6 @@ static struct fb_videomode *fb_create_modedb(unsigned char *edid, int *dbsize) if (mode == NULL) return NULL; - if (edid == NULL || !edid_checksum(edid) || - !edid_check_header(edid)) { - kfree(mode); - return NULL; - } - *dbsize = 0; DPRINTK(" Detailed Timings\n");