From patchwork Wed Nov 15 11:55:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Figa X-Patchwork-Id: 10059255 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 49C5A60231 for ; Wed, 15 Nov 2017 11:55:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F6DF28F6B for ; Wed, 15 Nov 2017 11:55:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32F0129F28; Wed, 15 Nov 2017 11:55:44 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable 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 E580C28F6B for ; Wed, 15 Nov 2017 11:55:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757304AbdKOLzb (ORCPT ); Wed, 15 Nov 2017 06:55:31 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:48640 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757227AbdKOLz3 (ORCPT ); Wed, 15 Nov 2017 06:55:29 -0500 Received: by mail-pg0-f65.google.com with SMTP id s11so12392570pgc.5 for ; Wed, 15 Nov 2017 03:55:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=FmMpn883QqHI9BCciaXqM9Ptqed18ZyDTUn9kyJPChk=; b=T46R+Yq9SOjDi7R++3E5r+kYRx3wyeUPYbZ1M3a+0NENpvO/0ZtQzPJGLx1qjEAWcZ mkVYSX2sstqc75tN7kYX1LPcFXUJmBKsm6//UNwF23dVWHsv365yPKZbM6hRHEr8OLob /XWbiS5/J3JvpQt5nfLwVvyqfvYN8ZzeCJq9Y= 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; bh=FmMpn883QqHI9BCciaXqM9Ptqed18ZyDTUn9kyJPChk=; b=PHcLVwMaDS6HU2jrlAVFP3EQMqOEqDYoduWcssd1mtPdVfthCChPdCfOEjPKtBiAQh K9SPiVyJEZMdx9cDwnl3XeZpNY9IxOg25vRxJte3FqNqBtdwFV7bwxJEvNwtgXQFnYZw EHxvE1xvLMmGPSHYAap9hHwMnXMqACk3RaPcWgmuR/wykbpGS3MNMlh3eBWzydCGEdNG IoYjZANbIIBHS1NNhtrzOZxAVDl5x1YOhNrn//rLS6lFYu8HPUpZ6st1ee8hHMGLnv+H m15OoWna7cVXWbxsgWdZtBY7LXvuLeZ+DPQZIEAkuXm0DtRmM4jl5FK3BWJQs6BL20iP evQw== X-Gm-Message-State: AJaThX7AMsrRRE+6UT8ER4FQsb0+NfVLQ0ey7FelkJJVev5pyv6XBgpr 0LWDuYD1TyjC9VH4GSyilvYgRAE3jSc= X-Google-Smtp-Source: AGs4zMacDq8QeHShLpEHWPUfpQm5dQGDVOokKziHK83I9ODsp+ztzh6EI53lvVoGk1Wwn9iw0g4oQw== X-Received: by 10.84.232.76 with SMTP id f12mr15325564pln.195.1510746928537; Wed, 15 Nov 2017 03:55:28 -0800 (PST) Received: from tfiga.tok.corp.google.com ([2401:fa00:4:1002:3ba3:2aea:6dcf:30b]) by smtp.gmail.com with ESMTPSA id 68sm28102816pfk.162.2017.11.15.03.55.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Nov 2017 03:55:27 -0800 (PST) From: Tomasz Figa To: linux-media@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , Sakari Ailus , Hans Verkuil , Sebastian Reichel , =?UTF-8?q?Niklas=20S=C3=B6derlund?= , Tomasz Figa Subject: [PATCH] media: v4l2-fwnode: Check subdev count after checking port Date: Wed, 15 Nov 2017 20:55:22 +0900 Message-Id: <20171115115522.30211-1-tfiga@chromium.org> X-Mailer: git-send-email 2.15.0.448.gf294e3d99a-goog 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 Current implementation of __v4l2_async_notifier_parse_fwnode_endpoints() checks first whether subdev_count >= subdev_max and only then whether the port being parsed matches the given port index. This triggers an error in otherwise valid cases of skipping ports that do not match. Fix this by moving the check below the port index check. Fixes: 9ca465312132 ("media: v4l: fwnode: Support generic parsing of graph endpoints in a device") Signed-off-by: Tomasz Figa --- drivers/media/v4l2-core/v4l2-fwnode.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c index 681b192420d9..fb72c7ac04d4 100644 --- a/drivers/media/v4l2-core/v4l2-fwnode.c +++ b/drivers/media/v4l2-core/v4l2-fwnode.c @@ -458,11 +458,6 @@ static int __v4l2_async_notifier_parse_fwnode_endpoints( if (!is_available) continue; - if (WARN_ON(notifier->num_subdevs >= notifier->max_subdevs)) { - ret = -EINVAL; - break; - } - if (has_port) { struct fwnode_endpoint ep; @@ -474,6 +469,11 @@ static int __v4l2_async_notifier_parse_fwnode_endpoints( continue; } + if (WARN_ON(notifier->num_subdevs >= notifier->max_subdevs)) { + ret = -EINVAL; + break; + } + ret = v4l2_async_notifier_fwnode_parse_endpoint( dev, notifier, fwnode, asd_struct_size, parse_endpoint); if (ret < 0)