Message ID | 20230614-topic-camss_grpah-v2-1-57d9d5e49038@linaro.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp238570vqt; Sat, 15 Jul 2023 09:08:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlHD2T53JLopq9USrRPlJ7gDX3lUpYalMctmb0hNFB1PlyFRyefOiTo58H4fD29Qjw3C2hIs X-Received: by 2002:a05:6402:2c4:b0:51e:281a:66a4 with SMTP id b4-20020a05640202c400b0051e281a66a4mr8886326edx.38.1689437328283; Sat, 15 Jul 2023 09:08:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689437328; cv=none; d=google.com; s=arc-20160816; b=Mi+PNhE2ooE+QIJBNvex1b4ZfopvTxstazHPD4q2rP/v7/BJYyTjvoyQOnEsH74l7f gadVm90UPliLx0VhFBB68sn+XcTYlXDqrCpK44403UfGs0iPFSFswMmZE6/2RQ3Dvmf+ Hvy2LVR2aunEvyM4frf0Sze10A3CKGNN6kfY0IrEm+XJjQ6e8DzFvLmclKrMLYdI730Z JVSZ22q04qaIHmCTJL1bT9u2nptj31HyjAvIYTdV5WrE0uAvcBaQBzbnDjcHjNCHEyAg GoQbWjRFpgG75j84WlR3k3wwh+uBq4+Ui+vcpo+qv/lQnrB3aWtnjHu2tA3yRAx0zYJN PsVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=S+djRnUBFZhHAwtTKh2Fe3WK0yWfTrmhbES8+t2drAg=; fh=CZENYx5Wib0nexJpLaDNkev/syFldPIPCxA6nwhQJX4=; b=wHmA6G4H8oHnjdJgPvG9azDVSXd1EyFJLl8AnHcDtTp/It1HqXDRjaXRhJzG4iqr7S hEH86cLOsJ7PgpoQJLhoYvmiz2U3QKObag+YGZWxLxmtrhPOKtePkTW4qV9bJQSfM+0t hs5jpDWm0nhNcCM2vN70DwiuQshU/rBUC4tPAU464TjIpwuO9EHc6JfhkUvJpCAmpQ7M Kj5ycBJVm6Jrxm37fbVzVn1XqULxk5zhf51FpShJCMtUCFWvo3gnxn+jg7O5Y34rMCLW nAQG3PA2Q4sq+v3jRvie55j/mietJhIU8GOdPdA5BEDeji+7A/n1bPUxH7s74G1mx3JO jQAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="F/WKXblS"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x2-20020aa7d6c2000000b0051fef960d1fsi2518860edr.616.2023.07.15.09.08.22; Sat, 15 Jul 2023 09:08:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="F/WKXblS"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230095AbjGOPh6 (ORCPT <rfc822;daweilics@gmail.com> + 99 others); Sat, 15 Jul 2023 11:37:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230090AbjGOPh5 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 15 Jul 2023 11:37:57 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 991932D7B for <linux-kernel@vger.kernel.org>; Sat, 15 Jul 2023 08:37:55 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-4fba1288bbdso4767909e87.1 for <linux-kernel@vger.kernel.org>; Sat, 15 Jul 2023 08:37:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689435474; x=1692027474; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=S+djRnUBFZhHAwtTKh2Fe3WK0yWfTrmhbES8+t2drAg=; b=F/WKXblS2846S3vhtFpEb05kbGFFIlENzJ3Y4pcrfI+SbTk2Y4XjeUHeOmPFoQ6m1O x80D1f1lE/oBOzx4W4O1p6tc67btDVnx+2hRulVnDMTiwRXyZQAf9uTj6ZZUtuQ0hAI6 yfHqyBm4seFNzJXZZK2fZloLVhR8leFeT9tBIW4yX2I/LTStYE2adgLNut/y49pqkE35 MGh8Nro99t/oT8bcG+4SdhtWqUs4KCesMWHLWoD3CjvFEDu/0xpQAYX8BmgCqP4l9nMu 1U424Wh7sGKB1YCW3gbgD3V6rlXd60Ajl9A14Wi0fImrx5I7WNAlfiNMlZ2/PcB00GN7 EHQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689435474; x=1692027474; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=S+djRnUBFZhHAwtTKh2Fe3WK0yWfTrmhbES8+t2drAg=; b=fLzFZTlpxzERtQj6l43Gv2uSWc58078bncRsx9EIKuyfNFRdGYFdCxT8d0nlZ1m5+H UOhlBqQ2viPSxDIovNlwdvBJHJlmrP2uN5noanixiyZOEMTKTpKLfBetPmALo+k7mC0u VxVQL0XrDP9zKYqFDuZ6JcFddEVrm8RUeIgMo+oC2wJHQhd3XsIjM2I6wZ70hXqPscvn Uy7wbj1nR/bCWgXUsXOvbrCvFejOjA96LNeHrWY4/vsgsYv9qrfEDPs8uFjZFqOLIGUl MDOSv1ErWCiUGOwGUJOGINN78N53dVPdI7dEIi2RCIO9v5iZj5pXNWqlwjjuzuWr+ad3 Sj5A== X-Gm-Message-State: ABy/qLapKZ/ws0zvz851diQXSkDECPFc+E16kh3yreYqRtw8XHaPVzQV pjbwgjd3rlSaWMFkGThONEXpOw== X-Received: by 2002:a05:6512:3f6:b0:4fb:9f93:365f with SMTP id n22-20020a05651203f600b004fb9f93365fmr6291643lfq.38.1689435473901; Sat, 15 Jul 2023 08:37:53 -0700 (PDT) Received: from [192.168.1.101] (abxi167.neoplus.adsl.tpnet.pl. [83.9.2.167]) by smtp.gmail.com with ESMTPSA id q30-20020ac2511e000000b004fbdeca7b79sm1925808lfb.247.2023.07.15.08.37.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jul 2023 08:37:53 -0700 (PDT) From: Konrad Dybcio <konrad.dybcio@linaro.org> Date: Sat, 15 Jul 2023 17:37:52 +0200 Subject: [PATCH v2] media: camss: Intepret OF graph connections more sensibly MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230614-topic-camss_grpah-v2-1-57d9d5e49038@linaro.org> X-B4-Tracking: v=1; b=H4sIAE+9smQC/32NQQrCMBAAv1L2bCRJ00o9+Q8pso1Js1CTsqlFK f270Qd4nIFhNsiOyWU4VxuwWylTigX0oQIbMI5O0L0waKlr2SojljSTFRYfOd9GnjGIuvMdGn8 yWloo3YDZiYEx2lDK+JymImd2nl6/0bUvHCgvid+/76q+9t9iVUKJxpuhUW2tpMfLRBE5HROP0 O/7/gEKWGVNyAAAAA== To: Robert Foss <rfoss@kernel.org>, Todor Tomov <todor.too@gmail.com>, Bryan O'Donoghue <bryan.odonoghue@linaro.org>, Andy Gross <agross@kernel.org>, Bjorn Andersson <andersson@kernel.org>, Mauro Carvalho Chehab <mchehab@kernel.org> Cc: Marijn Suijten <marijn.suijten@somainline.org>, Yassine Oudjana <y.oudjana@protonmail.com>, linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Konrad Dybcio <konrad.dybcio@linaro.org> X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1689435472; l=1614; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=IWx/Y65eu/NJcdTnG8aoRNmX5OhoUqPGvpZUr4ZM0kY=; b=YaoNNiOpYTAMnAIVRNlPWQcOOz1V+Rx9Cdsp/R84UIJLHhRbIeCqOvBhq1+8s3SEE9pgg6i/M jrYxMVUClulDsZVtzq87Uxvi5GyMWV97Pakq5etA31OhcYG6QKxXGTW X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771503435963564502 X-GMAIL-MSGID: 1771503435963564502 |
Series |
[v2] media: camss: Intepret OF graph connections more sensibly
|
|
Commit Message
Konrad Dybcio
July 15, 2023, 3:37 p.m. UTC
Not all endpoints of camss have to be populated. In fact, most of the
time they shouldn't be as n-th auxilliary cameras are usually ewaste.
Don't fail probing the entire camss even even one endpoint is not
linked and throw an error when none is found.
Signed-off-by: Konrad Dybcio <konrad.dybcio@linaro.org>
---
Changes in v2:
- Use if-else instead of the ternary operator (Bryan)
- Drop "RFC"
- Link to v1: https://lore.kernel.org/r/20230614-topic-camss_grpah-v1-1-5f4b516310fa@linaro.org
---
drivers/media/platform/qcom/camss/camss.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
---
base-commit: 7c2878be573282a9961c359b806ccf70afe1a6b6
change-id: 20230614-topic-camss_grpah-39f9a4f7420c
Best regards,
Comments
On Sat, Jul 15, 2023 at 05:37:52PM +0200, Konrad Dybcio wrote: > Not all endpoints of camss have to be populated. In fact, most of the > time they shouldn't be as n-th auxilliary cameras are usually ewaste. > > Don't fail probing the entire camss even even one endpoint is not > linked and throw an error when none is found. > > Signed-off-by: Konrad Dybcio <konrad.dybcio@linaro.org> > --- > Changes in v2: > - Use if-else instead of the ternary operator (Bryan) > - Drop "RFC" > - Link to v1: https://lore.kernel.org/r/20230614-topic-camss_grpah-v1-1-5f4b516310fa@linaro.org > --- > drivers/media/platform/qcom/camss/camss.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/drivers/media/platform/qcom/camss/camss.c b/drivers/media/platform/qcom/camss/camss.c > index 1ef26aea3eae..8b75197fa5d7 100644 > --- a/drivers/media/platform/qcom/camss/camss.c > +++ b/drivers/media/platform/qcom/camss/camss.c > @@ -1084,9 +1084,8 @@ static int camss_of_parse_ports(struct camss *camss) > > remote = of_graph_get_remote_port_parent(node); > if (!remote) { > - dev_err(dev, "Cannot get remote parent\n"); > - ret = -EINVAL; > - goto err_cleanup; > + of_node_put(node); This is broken and could potentially lead to a use after free. Specifically, the iteration macro already takes care of putting this reference. > + continue; > } > > csd = v4l2_async_nf_add_fwnode(&camss->notifier, > @@ -1105,7 +1104,10 @@ static int camss_of_parse_ports(struct camss *camss) > num_subdevs++; > } > > - return num_subdevs; > + if (num_subdevs) > + return num_subdevs; > + > + return -EINVAL; Please change this so that you test for the error condition rather than its inverse for symmetry. That is if (!num_subdevs) return -EINVAL; return num_subdevs; Returning EINVAL (invalid argument) is perhaps not the best choice, but the driver already does so here and in other places so keeping it for now should be fine. > err_cleanup: > of_node_put(node); Johan
On 17.07.2023 12:48, Johan Hovold wrote: > On Sat, Jul 15, 2023 at 05:37:52PM +0200, Konrad Dybcio wrote: >> Not all endpoints of camss have to be populated. In fact, most of the >> time they shouldn't be as n-th auxilliary cameras are usually ewaste. >> >> Don't fail probing the entire camss even even one endpoint is not >> linked and throw an error when none is found. >> >> Signed-off-by: Konrad Dybcio <konrad.dybcio@linaro.org> >> --- >> Changes in v2: >> - Use if-else instead of the ternary operator (Bryan) >> - Drop "RFC" >> - Link to v1: https://lore.kernel.org/r/20230614-topic-camss_grpah-v1-1-5f4b516310fa@linaro.org >> --- >> drivers/media/platform/qcom/camss/camss.c | 10 ++++++---- >> 1 file changed, 6 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/media/platform/qcom/camss/camss.c b/drivers/media/platform/qcom/camss/camss.c >> index 1ef26aea3eae..8b75197fa5d7 100644 >> --- a/drivers/media/platform/qcom/camss/camss.c >> +++ b/drivers/media/platform/qcom/camss/camss.c >> @@ -1084,9 +1084,8 @@ static int camss_of_parse_ports(struct camss *camss) >> >> remote = of_graph_get_remote_port_parent(node); >> if (!remote) { >> - dev_err(dev, "Cannot get remote parent\n"); >> - ret = -EINVAL; >> - goto err_cleanup; >> + of_node_put(node); > > This is broken and could potentially lead to a use after free. > > Specifically, the iteration macro already takes care of putting this > reference. /** * for_each_endpoint_of_node - iterate over every endpoint in a device node * @parent: parent device node containing ports and endpoints * @child: loop variable pointing to the current endpoint node * * When breaking out of the loop, of_node_put(child) has to be called manually. */ > >> + continue; >> } >> >> csd = v4l2_async_nf_add_fwnode(&camss->notifier, >> @@ -1105,7 +1104,10 @@ static int camss_of_parse_ports(struct camss *camss) >> num_subdevs++; >> } >> >> - return num_subdevs; >> + if (num_subdevs) >> + return num_subdevs; >> + >> + return -EINVAL; > > Please change this so that you test for the error condition rather than > its inverse for symmetry. That is > > if (!num_subdevs) > return -EINVAL; > > return num_subdevs; Right, this makes more sense Konrad > > Returning EINVAL (invalid argument) is perhaps not the best choice, but > the driver already does so here and in other places so keeping it for > now should be fine. > >> err_cleanup: >> of_node_put(node); > > Johan
On Mon, Jul 17, 2023 at 02:40:05PM +0200, Konrad Dybcio wrote: > On 17.07.2023 12:48, Johan Hovold wrote: > > On Sat, Jul 15, 2023 at 05:37:52PM +0200, Konrad Dybcio wrote: > >> diff --git a/drivers/media/platform/qcom/camss/camss.c b/drivers/media/platform/qcom/camss/camss.c > >> index 1ef26aea3eae..8b75197fa5d7 100644 > >> --- a/drivers/media/platform/qcom/camss/camss.c > >> +++ b/drivers/media/platform/qcom/camss/camss.c > >> @@ -1084,9 +1084,8 @@ static int camss_of_parse_ports(struct camss *camss) > >> > >> remote = of_graph_get_remote_port_parent(node); > >> if (!remote) { > >> - dev_err(dev, "Cannot get remote parent\n"); > >> - ret = -EINVAL; > >> - goto err_cleanup; > >> + of_node_put(node); > > > > This is broken and could potentially lead to a use after free. > > > > Specifically, the iteration macro already takes care of putting this > > reference. > /** > * for_each_endpoint_of_node - iterate over every endpoint in a device node > * @parent: parent device node containing ports and endpoints > * @child: loop variable pointing to the current endpoint node > * > * When breaking out of the loop, of_node_put(child) has to be called manually. > */ Please read this comment you just pasted here again as it seems you did not understand it. > > > >> + continue; And again, please remember to trim your replies. Including context after your reply is almost always wrong. Johan
diff --git a/drivers/media/platform/qcom/camss/camss.c b/drivers/media/platform/qcom/camss/camss.c index 1ef26aea3eae..8b75197fa5d7 100644 --- a/drivers/media/platform/qcom/camss/camss.c +++ b/drivers/media/platform/qcom/camss/camss.c @@ -1084,9 +1084,8 @@ static int camss_of_parse_ports(struct camss *camss) remote = of_graph_get_remote_port_parent(node); if (!remote) { - dev_err(dev, "Cannot get remote parent\n"); - ret = -EINVAL; - goto err_cleanup; + of_node_put(node); + continue; } csd = v4l2_async_nf_add_fwnode(&camss->notifier, @@ -1105,7 +1104,10 @@ static int camss_of_parse_ports(struct camss *camss) num_subdevs++; } - return num_subdevs; + if (num_subdevs) + return num_subdevs; + + return -EINVAL; err_cleanup: of_node_put(node);