Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp595054ybb; Thu, 28 Mar 2019 08:27:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqz9z6YbPIy+9/yX/SOsalTpYuiKAYrPEKuTTSgmTqYwD9ZcUG+4TSZHnEQ19tvfLbZiDhc/ X-Received: by 2002:a62:1e82:: with SMTP id e124mr41813993pfe.258.1553786825061; Thu, 28 Mar 2019 08:27:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553786825; cv=none; d=google.com; s=arc-20160816; b=y2SnSMG0oR6fID54doGf+AM64WigAYxfJPkSENG03//lVr/6025vYSWfwtptLwgWRR uqo/25qsRt8cIISzsjZ4y57n0fQTZMSXwmL9WtF+E2zZe2XPwJLx8xGlLAunJWuk/Df+ wUOLrzNl4/q7RAWEb6yzhYvqZgij7EwUkvAF7hrAT+6THqA7QmlP74MCZd5p10Ii5uGc bhSdw3QrH8UaZH66JpPnu122AAJz5ygxltUfoVonIuJ+5aO1on9yWZ+3Lexh4WRCryHY NBefIvkL+F4pk8Jymg3d6aEx7+FuTU3QD/YRKKEu0x5kImLnETmhEOhJ9t02L3ehMdb6 Yu8Q== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=EqxFprGRwOnhyMCFy+f9M83rfC3RH64k2Ji5wEkaAdU=; b=tuoX1LnjNRdUHTw7S/UlhrxeOG0UlLoU5OpK3gsKqzUoS9cGYfwO0q3hvXcFMIMG3r wWAlCXFZqQSYGGh2i/2ON04C+tBhkaiUFtOYiLwPqqIPX4WZwW4PNOZvrXmJKQYCe1ha Iu/bJJ1RDfeSQ+03rq2QIJp7tSyEDb8ty/TnvdzNwrMqHpSJhnZX+aGG/WulUhD32GK/ h4a95Y5izPXKTJrlpBt8fChZ7bWgUZdvKahHrikojOp3hnvQu6oVFr/2bizps91ZKAzX hLeXzZH3sEckDGZqBF6dOzV9Rg5Zid4I4X3w/j1E1PrqeAi0HK2BcBPTdqq7VD2pWieH loyQ== ARC-Authentication-Results: i=1; mx.google.com; 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 r4si21238936plo.416.2019.03.28.08.26.44; Thu, 28 Mar 2019 08:27:05 -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; 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 S1727086AbfC1P0K (ORCPT + 99 others); Thu, 28 Mar 2019 11:26:10 -0400 Received: from lb1-smtp-cloud7.xs4all.net ([194.109.24.24]:55429 "EHLO lb1-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725816AbfC1P0J (ORCPT ); Thu, 28 Mar 2019 11:26:09 -0400 Received: from [IPv6:2001:420:44c1:2579:7126:11db:5076:31b1] ([IPv6:2001:420:44c1:2579:7126:11db:5076:31b1]) by smtp-cloud7.xs4all.net with ESMTPA id 9Wuph7LWJNG8z9Wuthprsh; Thu, 28 Mar 2019 16:26:07 +0100 Subject: Re: [PATCH] media: rcar-vin: fix a potential NULL pointer dereference To: =?UTF-8?Q?Niklas_S=c3=b6derlund?= , Kangjie Lu Cc: pakki001@umn.edu, Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org References: <20190309070527.2657-1-kjlu@umn.edu> <20190309110217.GA5281@bigcity.dyn.berto.se> From: Hans Verkuil Message-ID: Date: Thu, 28 Mar 2019 16:26:03 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <20190309110217.GA5281@bigcity.dyn.berto.se> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4wfBEB/0puJGDittCRzgcErJ5iT0vB8q+I3QeuojGpSk72r7Zeew5ze69IljW770giFQZcGW78sr3t9dPyasq2QAUYMNfIwkJUVRtN+TRmnyHHFJaBaR9g X8crBnLbS1u8Gx0/f7FP8U0MkNiaeWF9w7ASsmAbDxqK8YCCRgNQ5v/86ULIHKVqWWyzXpU5Ko+rrX5FgrETx2VOo2E5ialSnQ438ctbLVAUDd1hYL2ERJVo nBQxv2PgsG5JjDM0CBgtwGzbcyN9qo4RnlImJKZRiXOmgoH5Enhia5rt4PkosjuiMQqfgYjONqDKNrEYkBEbXxdPbi/EvMsrFGgogh5wBsddS1sKIvgesiB5 DRGBnvnZk9UUdo1ej7rNGe9qFhpK8ioRbTIPr7937DpmkR+mx4cAm7KV+cyB4ouDQpjBWjwj3oBy5HlywmGZYfKWoA/wLRIaRHMnMdedqFK39eFw1RXI7Gel b497XBQayYXlbk5uG00jKveC/aoO1x4KdYRPUg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/9/19 12:02 PM, Niklas Söderlund wrote: > Hi Kangjie, > > Thanks for your patch. > > On 2019-03-09 01:05:27 -0600, Kangjie Lu wrote: >> In case of_match_node cannot find a match, the fix returns >> -EINVAL to avoid NULL pointer dereference. >> >> Signed-off-by: Kangjie Lu >> --- >> drivers/media/platform/rcar-vin/rcar-core.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c >> index f0719ce24b97..a058e2023ca8 100644 >> --- a/drivers/media/platform/rcar-vin/rcar-core.c >> +++ b/drivers/media/platform/rcar-vin/rcar-core.c >> @@ -266,6 +266,8 @@ static int rvin_group_init(struct rvin_group *group, struct rvin_dev *vin) >> >> match = of_match_node(vin->dev->driver->of_match_table, >> vin->dev->of_node); >> + if (unlikely(!match)) >> + return -EINVAL; > > I don't think this is needed. The driver depends on selects OF and if we > get this far we it is because we had a match already. The reason to call > of_match_node() here is simply to retrieve which of the possible > compatible strings was matched. > > Am I missing something? What scenario do you see where this can fail? And even if it can fail, then please drop the 'unlikely'. Regards, Hans > >> >> strscpy(mdev->driver_name, KBUILD_MODNAME, sizeof(mdev->driver_name)); >> strscpy(mdev->model, match->compatible, sizeof(mdev->model)); >> -- >> 2.17.1 >> >