From patchwork Sun Jul 23 18:16:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 9858535 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A4156600F5 for ; Sun, 23 Jul 2017 18:17:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E87F2854A for ; Sun, 23 Jul 2017 18:17:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93C1928552; Sun, 23 Jul 2017 18:17:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ACC0C28550 for ; Sun, 23 Jul 2017 18:17:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751568AbdGWSRA (ORCPT ); Sun, 23 Jul 2017 14:17:00 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:33372 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751439AbdGWSQr (ORCPT ); Sun, 23 Jul 2017 14:16:47 -0400 Received: by mail-wr0-f193.google.com with SMTP id y43so15830940wrd.0 for ; Sun, 23 Jul 2017 11:16:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0ZwoXzq5v/XDF4zAiCC7xwpRjKpP2aTBf+c52HurGks=; b=TNIYpGIUVooe/uEIMhEfU5vmv+Yg7ghZHI8R4NvVV4EDHaV5GR4RN3TALc1LI4z91+ 2LFvZPhywYzOf9yW+XU++Dg77J6y1V6kvYc7Mh/JgUq4URrVixgb1ldlxNsRaqLfD4uY UGRd+B62LxGkOAQHrwRy2yAxtXdm/Ega+WqMaRFgbab/IIcNQQMRY1YD1XF/nmOxDzpK +f5b/io0ba1J9LzzRfXrUyjdwtGHdcUzd3awtARQyu2v54uP4bxiFnGVpvCI3ZIEhO3f YKtPshQmTkeoC7J4FH3ffxETrCfSv0ecduGzrhl2IwtqdZ7kHI7akBz0ycOYM8PBrVRF EQIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0ZwoXzq5v/XDF4zAiCC7xwpRjKpP2aTBf+c52HurGks=; b=bSTTrs2ejmjSP5xQXb8gvC6H9QZG6uFLy+Q6VBrTCYZMla9J+G/3gNXOhQBMKwzwDP PRcI91gyw6DuzvTZhja2+JNvWfMJAVG/1lNMqq4xQ+kEWG0d2W9cmsqnUR6Vr8WQ44cu tG+K2Iy2Cu0NSdQ/7NxdRWgPuAwuYJcOU4ZoRvcHIgKDFu1C+R+j5oY3Th9oMwHFseAc bl0OKFk9ECXhiBxMnJnatMJmyCmIAhX1cuSkFg7J+w/5TIGYr2LZ4Xr6aDawXD5As1tF JJVsoB+JYEIORhTKUE9UTGUhWhnM0m4l0UfgpZGkGr9TbHTLGHZB6yuporshuawzKMVG 1HlQ== X-Gm-Message-State: AIVw112iQlLL0NvFw06SOTho5jRXR0tA7OJ1aYbR6ZTZI0RNCJaJJL6c LsM0k8VVbJTSLeC0 X-Received: by 10.223.134.39 with SMTP id 36mr10172675wrv.244.1500833806566; Sun, 23 Jul 2017 11:16:46 -0700 (PDT) Received: from dvbdev.wuest.de (ip-84-118-193-88.unity-media.net. [84.118.193.88]) by smtp.gmail.com with ESMTPSA id 93sm13247338wra.82.2017.07.23.11.16.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 23 Jul 2017 11:16:46 -0700 (PDT) From: Daniel Scheller To: linux-media@vger.kernel.org, mchehab@kernel.org, mchehab@s-opensource.com Cc: r.scobie@clear.net.nz, jasmin@anw.at, d_spingler@freenet.de, Manfred.Knick@t-online.de, rjkm@metzlerbros.de Subject: [PATCH RESEND 12/14] [media] ddbridge: fix dereference before check Date: Sun, 23 Jul 2017 20:16:28 +0200 Message-Id: <20170723181630.19526-13-d.scheller.oss@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170723181630.19526-1-d.scheller.oss@gmail.com> References: <20170723181630.19526-1-d.scheller.oss@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Daniel Scheller Both ts_release() and ts_open() can use "output" before check (smatch): drivers/media/pci/ddbridge/ddbridge-core.c:816 ts_release() warn: variable dereferenced before check 'output' (see line 809) drivers/media/pci/ddbridge/ddbridge-core.c:836 ts_open() warn: variable dereferenced before check 'output' (see line 828) Fix by performing checks on those pointers. Cc: Ralph Metzler Signed-off-by: Daniel Scheller Tested-by: Richard Scobie Tested-by: Jasmin Jessich Tested-by: Dietmar Spingler Tested-by: Manfred Knick --- drivers/media/pci/ddbridge/ddbridge-core.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c index e3119351b9a1..98ead4ee8d2f 100644 --- a/drivers/media/pci/ddbridge/ddbridge-core.c +++ b/drivers/media/pci/ddbridge/ddbridge-core.c @@ -737,8 +737,13 @@ static unsigned int ts_poll(struct file *file, poll_table *wait) static int ts_release(struct inode *inode, struct file *file) { struct dvb_device *dvbdev = file->private_data; - struct ddb_output *output = dvbdev->priv; - struct ddb_input *input = output->port->input[0]; + struct ddb_output *output = NULL; + struct ddb_input *input = NULL; + + if (dvbdev) { + output = dvbdev->priv; + input = output->port->input[0]; + } if ((file->f_flags & O_ACCMODE) == O_RDONLY) { if (!input) @@ -756,8 +761,13 @@ static int ts_open(struct inode *inode, struct file *file) { int err; struct dvb_device *dvbdev = file->private_data; - struct ddb_output *output = dvbdev->priv; - struct ddb_input *input = output->port->input[0]; + struct ddb_output *output = NULL; + struct ddb_input *input = NULL; + + if (dvbdev) { + output = dvbdev->priv; + input = output->port->input[0]; + } if ((file->f_flags & O_ACCMODE) == O_RDONLY) { if (!input)