Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3911400imm; Mon, 8 Oct 2018 11:33:35 -0700 (PDT) X-Google-Smtp-Source: ACcGV62wJhF0taCvN4DJcK90ZllMy0HOjf9QgVY6JQx04R9IvJeuz2j2ZDF9k+gi03Rlhyfu/GB8 X-Received: by 2002:a17:902:5a89:: with SMTP id r9-v6mr24870532pli.95.1539023615578; Mon, 08 Oct 2018 11:33:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539023615; cv=none; d=google.com; s=arc-20160816; b=MdiP/PiwzOxOrFYUXR8YFCGm2jSCJ0STP8qxgr+Mbbe3Y4TkQyO+o9mf9uItwJ7aSP pRv7uDCO+Pp1Ud+WNumwUyNxh74/lYZe8hJgENN6hteZs7kq9ylHVvXiYCOqhm3T9i8X XBBZtJY4bYddu9YCdPgPGaxPcProqyB51qCn21fWmASykAKE+lRP6SB8uqwaJ8BCUF9C TzEvx6BwrdNTBeNpq3rFLNlqlagfE/SLPFJKwDMfYE1+7VEVKxAUbyXaFZ1x1wuRtmmL sgR3YWvpyL0XnVQum+laUrUQ5iztY1lz1h6SPXcc1mheV8lRPh9B+Sgbd8cz1X8yM52U HfLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ItYtjZYukGy5iL2dEJL498cqGBr63wzsC9Qk1iH2Dtw=; b=Hr4FM8iXS1PxSakemIbiNwXnBnG+o9QZXvwJP9OwkRi5N0hXfERKuiJFetvHP1z+dj gZHxeDHa6601+wQKHJK9bDVyy8QhaxG2rS6lqbuG+JuOVncGCnw4oTykqJXVXXXU64U4 3klK1dZnttpCwY4QlpnvylPZo9/2q71R7BqsRZHbPuleaeSz7QWcsfQ5yiidj8Nw5GYT XJlXT+vhIPJOJvtPMNQl3YGhhToIvm9KQGvyQkFlxI1riHLECySu7XM2GIUnJLYlhGiD h0cvZLm0ibOBxVpxsT0i2J22C48gpkAv5wOjsxE3muZ9g+tXjdaFLqLVVM1692oeHjRe b58w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="t3K/GDF6"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y125-v6si16978544pgb.14.2018.10.08.11.33.20; Mon, 08 Oct 2018 11:33:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="t3K/GDF6"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726770AbeJIBqC (ORCPT + 99 others); Mon, 8 Oct 2018 21:46:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:55766 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726418AbeJIBqB (ORCPT ); Mon, 8 Oct 2018 21:46:01 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5BBAA2087D; Mon, 8 Oct 2018 18:32:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539023578; bh=OoC5Ys0+FOT6qwpNZkFO1Qwf2vrg7gsvNVz+sFMJ/YE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t3K/GDF6KdfOTsXb4t57W9WqNxnGZaCQoJPGbkengQWs2z0h09132Q8SHd9rl019Z yqfwGXFJXxn0dt6/RGZ7CqXIh71qBZMs/iFFfwLVsLLZ+XwM7xMxsjMQ+Sfx91Mp4E IP9wVZ1jM8fDA/m0ZbMszUpaGOOSCk9Hq0DAw4OE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexey Khoroshilov , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.4 014/113] media: fsl-viu: fix error handling in viu_of_probe() Date: Mon, 8 Oct 2018 20:30:15 +0200 Message-Id: <20181008175531.557704748@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175530.864641368@linuxfoundation.org> References: <20181008175530.864641368@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexey Khoroshilov [ Upstream commit 662a99e145661c2b35155cf375044deae9b79896 ] viu_of_probe() ignores fails in i2c_get_adapter(), tries to unlock uninitialized mutex on error path. The patch streamlining the error handling in viu_of_probe(). Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Alexey Khoroshilov Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/media/platform/fsl-viu.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) --- a/drivers/media/platform/fsl-viu.c +++ b/drivers/media/platform/fsl-viu.c @@ -1417,7 +1417,7 @@ static int viu_of_probe(struct platform_ sizeof(struct viu_reg), DRV_NAME)) { dev_err(&op->dev, "Error while requesting mem region\n"); ret = -EBUSY; - goto err; + goto err_irq; } /* remap registers */ @@ -1425,7 +1425,7 @@ static int viu_of_probe(struct platform_ if (!viu_regs) { dev_err(&op->dev, "Can't map register set\n"); ret = -ENOMEM; - goto err; + goto err_irq; } /* Prepare our private structure */ @@ -1433,7 +1433,7 @@ static int viu_of_probe(struct platform_ if (!viu_dev) { dev_err(&op->dev, "Can't allocate private structure\n"); ret = -ENOMEM; - goto err; + goto err_irq; } viu_dev->vr = viu_regs; @@ -1449,16 +1449,21 @@ static int viu_of_probe(struct platform_ ret = v4l2_device_register(viu_dev->dev, &viu_dev->v4l2_dev); if (ret < 0) { dev_err(&op->dev, "v4l2_device_register() failed: %d\n", ret); - goto err; + goto err_irq; } ad = i2c_get_adapter(0); + if (!ad) { + ret = -EFAULT; + dev_err(&op->dev, "couldn't get i2c adapter\n"); + goto err_v4l2; + } v4l2_ctrl_handler_init(&viu_dev->hdl, 5); if (viu_dev->hdl.error) { ret = viu_dev->hdl.error; dev_err(&op->dev, "couldn't register control\n"); - goto err_vdev; + goto err_i2c; } /* This control handler will inherit the control(s) from the sub-device(s). */ @@ -1476,7 +1481,7 @@ static int viu_of_probe(struct platform_ vdev = video_device_alloc(); if (vdev == NULL) { ret = -ENOMEM; - goto err_vdev; + goto err_hdl; } *vdev = viu_template; @@ -1497,7 +1502,7 @@ static int viu_of_probe(struct platform_ ret = video_register_device(viu_dev->vdev, VFL_TYPE_GRABBER, -1); if (ret < 0) { video_device_release(viu_dev->vdev); - goto err_vdev; + goto err_unlock; } /* enable VIU clock */ @@ -1505,12 +1510,12 @@ static int viu_of_probe(struct platform_ if (IS_ERR(clk)) { dev_err(&op->dev, "failed to lookup the clock!\n"); ret = PTR_ERR(clk); - goto err_clk; + goto err_vdev; } ret = clk_prepare_enable(clk); if (ret) { dev_err(&op->dev, "failed to enable the clock!\n"); - goto err_clk; + goto err_vdev; } viu_dev->clk = clk; @@ -1521,7 +1526,7 @@ static int viu_of_probe(struct platform_ if (request_irq(viu_dev->irq, viu_intr, 0, "viu", (void *)viu_dev)) { dev_err(&op->dev, "Request VIU IRQ failed.\n"); ret = -ENODEV; - goto err_irq; + goto err_clk; } mutex_unlock(&viu_dev->lock); @@ -1529,16 +1534,19 @@ static int viu_of_probe(struct platform_ dev_info(&op->dev, "Freescale VIU Video Capture Board\n"); return ret; -err_irq: - clk_disable_unprepare(viu_dev->clk); err_clk: - video_unregister_device(viu_dev->vdev); + clk_disable_unprepare(viu_dev->clk); err_vdev: - v4l2_ctrl_handler_free(&viu_dev->hdl); + video_unregister_device(viu_dev->vdev); +err_unlock: mutex_unlock(&viu_dev->lock); +err_hdl: + v4l2_ctrl_handler_free(&viu_dev->hdl); +err_i2c: i2c_put_adapter(ad); +err_v4l2: v4l2_device_unregister(&viu_dev->v4l2_dev); -err: +err_irq: irq_dispose_mapping(viu_irq); return ret; }