From patchwork Fri Feb 3 14:05:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 93174 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp634357obz; Fri, 3 Feb 2017 06:05:37 -0800 (PST) X-Received: by 10.99.65.1 with SMTP id o1mr17907664pga.93.1486130737148; Fri, 03 Feb 2017 06:05:37 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k88si25557859pfk.99.2017.02.03.06.05.36; Fri, 03 Feb 2017 06:05:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-samsung-soc-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753357AbdBCOFg (ORCPT + 4 others); Fri, 3 Feb 2017 09:05:36 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:31424 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752949AbdBCOFf (ORCPT ); Fri, 3 Feb 2017 09:05:35 -0500 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OKS00IUWXT7L740@mailout2.w1.samsung.com>; Fri, 03 Feb 2017 14:05:31 +0000 (GMT) Received: from eusmges2.samsung.com (unknown [203.254.199.241]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20170203140530eucas1p271e05bec6e122d6cb0277dabba68c16e~fzAaeou0Q0358603586eucas1p2Q; Fri, 3 Feb 2017 14:05:30 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2.samsung.com (EUCPMTA) with SMTP id 41.10.30614.A2E84985; Fri, 3 Feb 2017 14:05:30 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170203140530eucas1p17e9d0bbb29da881bae025e8e3bc7cbbb~fzAZ1EUls3232032320eucas1p1v; Fri, 3 Feb 2017 14:05:30 +0000 (GMT) X-AuditID: cbfec7f1-f793f6d000007796-91-58948e2a4513 Received: from eusync4.samsung.com ( [203.254.199.214]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id BB.9C.10233.92E84985; Fri, 3 Feb 2017 14:05:29 +0000 (GMT) Received: from AMDC2765.digital.local ([106.116.147.25]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OKS006ZWXT16T00@eusync4.samsung.com>; Fri, 03 Feb 2017 14:05:29 +0000 (GMT) From: Marek Szyprowski To: linux-media@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Sylwester Nawrocki , Andrzej Hajda , Krzysztof Kozlowski Subject: [PATCH] media: s5p-mfc: Fix initialization of internal structures Date: Fri, 03 Feb 2017 15:05:18 +0100 Message-id: <1486130718-25998-1-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrLIsWRmVeSWpSXmKPExsWy7djPc7pafVMiDH7vVLG4te4cq8X58xvY LXo2bGW1mHF+H5PF2iN32S0Ov2lndWDz2LSqk82jb8sqRo/Pm+QCmKO4bFJSczLLUov07RK4 Mo5c38lY0CFa0T1HvIHxj2AXIyeHhICJxJTVv5ghbDGJC/fWs3UxcnEICSxllOha9Z0JwvnM KLHl/WEWmI71y7tYIRLLGCWaGm5CtTQwSaxbcJwdpIpNwFCi620XG4gtIuAksXDWX3aQImaB NYwSu/c8YQJJCAt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JJ4QxNDc0tDI2MLC3MjIyVx3qkfroQLCaQnlqRmp6YWpBbB9DFxcEo1MAa4TFry qqozbSPHk/V9syTv3S+smHLoBUP3i42W659uO5bitO2RHreu+eVz82oe73jjUTH52ssC9doz EYe6+e8E7GG4Ur0t89HKNwKT0thXXKw4uD7J7OOexbNmykb3T/+un3Kmw70//asQy9RAnv+/ Ylr1PT5kMv8TMjn6r17ly1T3w133k8SVWIozEg21mIuKEwHofZMqVQIAAA== X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170203140530eucas1p17e9d0bbb29da881bae025e8e3bc7cbbb X-Msg-Generator: CA X-Sender-IP: 182.198.249.180 X-Local-Sender: =?utf-8?q?Marek_Szyprowski=1BSRPOL-Kernel_=28TP=29=1B?= =?utf-8?b?7IK87ISx7KCE7J6QG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Global-Sender: =?utf-8?q?Marek_Szyprowski=1BSRPOL-Kernel_=28TP=29=1BSam?= =?utf-8?q?sung_Electronics=1BSenior_Software_Engineer?= X-Sender-Code: =?utf-8?q?C10=1BEHQ=1BC10CD02CD027392?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20170203140530eucas1p17e9d0bbb29da881bae025e8e3bc7cbbb X-RootMTR: 20170203140530eucas1p17e9d0bbb29da881bae025e8e3bc7cbbb References: Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org Initialize members of the internal device and context structures as early as possible to avoid access to uninitialized objects on initialization failures. If loading firmware or creating of the hardware instance fails, driver will access device or context queue in error handling path, which might not be initialized yet, what causes kernel panic. Fix this by moving initialization of all static members as early as possible. Signed-off-by: Marek Szyprowski --- drivers/media/platform/s5p-mfc/s5p_mfc.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Acked-by: Andrzej Hajda Reviewed-by: Javier Martinez Canillas Tested-by: Javier Martinez Canillas diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c b/drivers/media/platform/s5p-mfc/s5p_mfc.c index bb0a5887c9a9..05fe82be6584 100644 --- a/drivers/media/platform/s5p-mfc/s5p_mfc.c +++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c @@ -764,6 +764,7 @@ static int s5p_mfc_open(struct file *file) ret = -ENOMEM; goto err_alloc; } + init_waitqueue_head(&ctx->queue); v4l2_fh_init(&ctx->fh, vdev); file->private_data = &ctx->fh; v4l2_fh_add(&ctx->fh); @@ -899,7 +900,6 @@ static int s5p_mfc_open(struct file *file) mfc_err("Failed to initialize videobuf2 queue(output)\n"); goto err_queue_init; } - init_waitqueue_head(&ctx->queue); mutex_unlock(&dev->mfc_mutex); mfc_debug_leave(); return ret; @@ -1218,6 +1218,13 @@ static int s5p_mfc_probe(struct platform_device *pdev) vb2_dma_contig_set_max_seg_size(dev->mem_dev_r, DMA_BIT_MASK(32)); mutex_init(&dev->mfc_mutex); + init_waitqueue_head(&dev->queue); + dev->hw_lock = 0; + INIT_WORK(&dev->watchdog_work, s5p_mfc_watchdog_worker); + atomic_set(&dev->watchdog_cnt, 0); + init_timer(&dev->watchdog_timer); + dev->watchdog_timer.data = (unsigned long)dev; + dev->watchdog_timer.function = s5p_mfc_watchdog; ret = s5p_mfc_alloc_firmware(dev); if (ret) @@ -1226,7 +1233,6 @@ static int s5p_mfc_probe(struct platform_device *pdev) ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev); if (ret) goto err_v4l2_dev_reg; - init_waitqueue_head(&dev->queue); /* decoder */ vfd = video_device_alloc(); @@ -1263,13 +1269,6 @@ static int s5p_mfc_probe(struct platform_device *pdev) video_set_drvdata(vfd, dev); platform_set_drvdata(pdev, dev); - dev->hw_lock = 0; - INIT_WORK(&dev->watchdog_work, s5p_mfc_watchdog_worker); - atomic_set(&dev->watchdog_cnt, 0); - init_timer(&dev->watchdog_timer); - dev->watchdog_timer.data = (unsigned long)dev; - dev->watchdog_timer.function = s5p_mfc_watchdog; - /* Initialize HW ops and commands based on MFC version */ s5p_mfc_init_hw_ops(dev); s5p_mfc_init_hw_cmds(dev);