Message ID | 20221014183459.181567-5-prabhakar.mahadev-lad.rj@bp.renesas.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp325760wrs; Fri, 14 Oct 2022 11:36:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6QAKXw9YHESK04n9FDItKGBiDeKKvKuo4fgxxKza7HrD2fQ0cdRY5kNYQ0wdMcc3z3mY91 X-Received: by 2002:a63:2a02:0:b0:42b:2711:d534 with SMTP id q2-20020a632a02000000b0042b2711d534mr5644029pgq.176.1665772618941; Fri, 14 Oct 2022 11:36:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665772618; cv=none; d=google.com; s=arc-20160816; b=OI4z2cAZu1yXISwaQyZqHBNHitu4zWVuBlZ0aWPs3iA3B0mR4YC2ZeSgxpukxCikTP 1TTbMlIAc6sagng9/OW30KuVd38xesOj6TDkeF9JyrH3/RELqKRJUyjzOAxjq2Ltvqwa SvmJWehWWZ1vRmf39wDrcIXeUleLFV4ko9tnri1X2evl2VR5oImR+NIKJJQEGKQwZCUC PxHqRGVCjuPytQCqai7krBufn4cluygGEVfzhopDKbGlL8Tms9/dHjOj62+wvMYLG7vL LyplE0yoQ2/yMyFHbHpn1qHg5nMbaI7jWPQifAWG4KBPZyQWUUi6niz3unwlE6QR/N7c pS4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FPNinP5NcVb9ViQFD23z9JvBzsucMh06jMRDsBjL9jk=; b=Ay0KS7+H6nCTpFt+OLy3ke9BGAPciDkW2cxNBP5nciS1inGdLaYsWlxBrcLbr8Vq13 YzYUBg9zhw8Q+7Bwiave1ZekPiGlf0lX4YeGy00vwuoN1QrwNeeYcmzVqiQ5YuwRbrb8 jie4FtSGGJO+jaY0RAafJQa08GHpLGovbqsDtYvGtSzuaL/hIBhpFVBpktJriYQgJVWj 3zga8Ab6cYa/KHoZ/uU6EGxEtVH8nocOePBctrub1mnTH/jHubYirJoA8gUXpgALrmQZ 9tB+tXrLIdXxOA1qTR5Y4OPuo1dVh+I83T6N4PlrUoe4BCGx+9Tk4KM1VIf6RXqHsJRG irig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=K3ZIGnYT; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k18-20020a170902c41200b00172e069021dsi4073808plk.469.2022.10.14.11.36.45; Fri, 14 Oct 2022 11:36:58 -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=@gmail.com header.s=20210112 header.b=K3ZIGnYT; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229683AbiJNSfy (ORCPT <rfc822;ouuuleilei@gmail.com> + 99 others); Fri, 14 Oct 2022 14:35:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231130AbiJNSfb (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 14 Oct 2022 14:35:31 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 857C4A7A99; Fri, 14 Oct 2022 11:35:23 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id r13so8846637wrj.11; Fri, 14 Oct 2022 11:35:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FPNinP5NcVb9ViQFD23z9JvBzsucMh06jMRDsBjL9jk=; b=K3ZIGnYTG2IW438XZKj0WhZ+OGMxdF8aRcvKK9NtgqDu/HP4htzpzZP5o4f6MqSCNn hoDyxzJP5TSGezWugWfiKaUdYwng+RoV0hCpMm+dava7Kf8Y7i0X09qMAxg58qrqFS56 49X+On/sn8fp+tQfes6gRmGRmp6yJskbhBVD6gjINZ3nhKtrcNSe0b434f/2idDVba5S 1ASPzAUmhBiGb6aXngjNu3ZSL78xhXOqlqgLmad4HP7ToGqNIUolv8EJgMdkr2CVv/4T 1M4k2F5fpbP+82IboWoD+wVeYUnHJK19a3gP/dWYxvpiwZ7kxEjqe/N8cQM7oFz3e31Q PnMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FPNinP5NcVb9ViQFD23z9JvBzsucMh06jMRDsBjL9jk=; b=tbNvugd/stySTJmTLWIHLVs8t61V/u57XlkwRLBS0IKjTwpVH/u1dQ7q340BPOt9j2 f1LQ4WlvbPHv2RTIsDVu0TX+/qtXWaIHOt441EXXopeaLlkVsDgRPO1PTbL/iMhwHn5v tR+cuc3bMa99UdkFCE20KeTJ15HmUpaLvEGseiuNCGhqJ7f44gQYLUgiKUWYO1HNucnw TxZzfV2WLrVG4FjmCKRcxhF62OUTH1cdaot3YJDGXoCM22J4n8X4y8lO3RBUyagw2TXj skZY6PeOr0P5H+xSuJr4pRhWxGzQxZ9h+WgCZUznh3iNjmim5iZIPGJVXkls4ObboeQb g1AA== X-Gm-Message-State: ACrzQf0UFDVOWALkJKDvyXeoX1117ojsYK/tcOeZAt7SiyCCdNuxy/iP GrASPFoJRC/UUv4mcn0DEa8= X-Received: by 2002:a05:6000:1565:b0:22f:1407:9bfd with SMTP id 5-20020a056000156500b0022f14079bfdmr4240073wrz.620.1665772521673; Fri, 14 Oct 2022 11:35:21 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2501:c701:fc4d:6548:d8bd:5bd]) by smtp.gmail.com with ESMTPSA id h10-20020a5d504a000000b0022a403954c3sm2485410wrt.42.2022.10.14.11.35.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 11:35:21 -0700 (PDT) From: Prabhakar <prabhakar.csengg@gmail.com> X-Google-Original-From: Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> To: Sakari Ailus <sakari.ailus@linux.intel.com>, Laurent Pinchart <laurent.pinchart@ideasonboard.com>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Rob Herring <robh+dt@kernel.org>, Mauro Carvalho Chehab <mchehab@kernel.org>, Hans Verkuil <hverkuil@xs4all.nl> Cc: Shawn Tu <shawnx.tu@intel.com>, Jacopo Mondi <jacopo@jmondi.org>, linux-media@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar <prabhakar.csengg@gmail.com>, Biju Das <biju.das.jz@bp.renesas.com>, Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Subject: [PATCH v2 4/5] media: i2c: ov5645: Return zero for s_stream(0) Date: Fri, 14 Oct 2022 19:34:58 +0100 Message-Id: <20221014183459.181567-5-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221014183459.181567-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20221014183459.181567-1-prabhakar.mahadev-lad.rj@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746689189507507635?= X-GMAIL-MSGID: =?utf-8?q?1746689189507507635?= |
Series |
media: i2c: ov5645 driver enhancements
|
|
Commit Message
Lad, Prabhakar
Oct. 14, 2022, 6:34 p.m. UTC
From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Always return zero while stopping the stream as the caller will ignore the return value. This patch drops checking the return value of ov5645_write_reg() and continues further in the code path while stopping stream. The user anyway gets an error message in case ov5645_write_reg() fails. Suggested-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> --- v1->v2 * New patch --- drivers/media/i2c/ov5645.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
Comments
Hi Prabhakar, Thank you for the patch. On Fri, Oct 14, 2022 at 07:34:58PM +0100, Prabhakar wrote: > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > > Always return zero while stopping the stream as the caller will ignore the > return value. > > This patch drops checking the return value of ov5645_write_reg() and > continues further in the code path while stopping stream. The user anyway > gets an error message in case ov5645_write_reg() fails. Continuing all the way to pm_runtime_put() is fine, but I don't think the function should return 0. It's not up to the driver to decide if a failure would be useful to signal to the caller or not. > Suggested-by: Sakari Ailus <sakari.ailus@linux.intel.com> > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > --- > v1->v2 > * New patch > --- > drivers/media/i2c/ov5645.c | 11 ++++------- > 1 file changed, 4 insertions(+), 7 deletions(-) > > diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c > index a0b9d0c43b78..b3825294aaf1 100644 > --- a/drivers/media/i2c/ov5645.c > +++ b/drivers/media/i2c/ov5645.c > @@ -995,14 +995,11 @@ static int ov5645_s_stream(struct v4l2_subdev *subdev, int enable) > if (ret < 0) > goto err_rpm_put; > } else { > - ret = ov5645_write_reg(ov5645, OV5645_IO_MIPI_CTRL00, 0x40); > - if (ret < 0) > - return ret; > + ov5645_write_reg(ov5645, OV5645_IO_MIPI_CTRL00, 0x40); > + > + ov5645_write_reg(ov5645, OV5645_SYSTEM_CTRL0, > + OV5645_SYSTEM_CTRL0_STOP); > > - ret = ov5645_write_reg(ov5645, OV5645_SYSTEM_CTRL0, > - OV5645_SYSTEM_CTRL0_STOP); > - if (ret < 0) > - return ret; > pm_runtime_put(ov5645->dev); > } >
Hi Laurent, On Sat, Oct 15, 2022 at 09:25:37AM +0300, Laurent Pinchart wrote: > Hi Prabhakar, > > Thank you for the patch. > > On Fri, Oct 14, 2022 at 07:34:58PM +0100, Prabhakar wrote: > > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > > > > Always return zero while stopping the stream as the caller will ignore the > > return value. > > > > This patch drops checking the return value of ov5645_write_reg() and > > continues further in the code path while stopping stream. The user anyway > > gets an error message in case ov5645_write_reg() fails. > > Continuing all the way to pm_runtime_put() is fine, but I don't think > the function should return 0. It's not up to the driver to decide if a > failure would be useful to signal to the caller or not. If the function returns an error when disabling streaming, what is the expected power state of the device after this? The contract between the caller and the callee is that the state is not changed if there is an error. This is a special case as very few callers check the return value for streamoff operation and those that do generally just print something. I've never seen a caller trying to prevent streaming off in this case, for instance. Of course we could document that streaming off always counts as succeeded (e.g. decreasing device's runtime PM usage_count) while it could return an informational error code. But I wonder if anyone would ever benefit from that somehow. :-) > > > Suggested-by: Sakari Ailus <sakari.ailus@linux.intel.com> > > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > > --- > > v1->v2 > > * New patch > > --- > > drivers/media/i2c/ov5645.c | 11 ++++------- > > 1 file changed, 4 insertions(+), 7 deletions(-) > > > > diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c > > index a0b9d0c43b78..b3825294aaf1 100644 > > --- a/drivers/media/i2c/ov5645.c > > +++ b/drivers/media/i2c/ov5645.c > > @@ -995,14 +995,11 @@ static int ov5645_s_stream(struct v4l2_subdev *subdev, int enable) > > if (ret < 0) > > goto err_rpm_put; > > } else { > > - ret = ov5645_write_reg(ov5645, OV5645_IO_MIPI_CTRL00, 0x40); > > - if (ret < 0) > > - return ret; > > + ov5645_write_reg(ov5645, OV5645_IO_MIPI_CTRL00, 0x40); > > + > > + ov5645_write_reg(ov5645, OV5645_SYSTEM_CTRL0, > > + OV5645_SYSTEM_CTRL0_STOP); > > > > - ret = ov5645_write_reg(ov5645, OV5645_SYSTEM_CTRL0, > > - OV5645_SYSTEM_CTRL0_STOP); > > - if (ret < 0) > > - return ret; > > pm_runtime_put(ov5645->dev); > > } > > >
Hi Sakari, On Sat, Oct 15, 2022 at 09:35:12PM +0000, Sakari Ailus wrote: > On Sat, Oct 15, 2022 at 09:25:37AM +0300, Laurent Pinchart wrote: > > On Fri, Oct 14, 2022 at 07:34:58PM +0100, Prabhakar wrote: > > > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > > > > > > Always return zero while stopping the stream as the caller will ignore the > > > return value. > > > > > > This patch drops checking the return value of ov5645_write_reg() and > > > continues further in the code path while stopping stream. The user anyway > > > gets an error message in case ov5645_write_reg() fails. > > > > Continuing all the way to pm_runtime_put() is fine, but I don't think > > the function should return 0. It's not up to the driver to decide if a > > failure would be useful to signal to the caller or not. > > If the function returns an error when disabling streaming, what is the > expected power state of the device after this? That's up to us to decide :-) > The contract between the caller and the callee is that the state is not > changed if there is an error. For most APIs, but that's not universal. > This is a special case as very few callers > check the return value for streamoff operation and those that do generally > just print something. I've never seen a caller trying to prevent streaming > off in this case, for instance. I think the stream off call should proceed and try to power off the device even if an error occurs along the way, i.e. it shouldn't return upon the first detected error. > Of course we could document that streaming off always counts as succeeded > (e.g. decreasing device's runtime PM usage_count) while it could return an > informational error code. But I wonder if anyone would ever benefit from > that somehow. :-) I think it could be useful to propagate errors up to inform the user that something wrong happened. That would involve fixing lots of drivers along the call chain though, so there's no urgency for the ov5645 to do so, but isn't it better to propagate the error code instead of hiding the issue ? > > > Suggested-by: Sakari Ailus <sakari.ailus@linux.intel.com> > > > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > > > --- > > > v1->v2 > > > * New patch > > > --- > > > drivers/media/i2c/ov5645.c | 11 ++++------- > > > 1 file changed, 4 insertions(+), 7 deletions(-) > > > > > > diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c > > > index a0b9d0c43b78..b3825294aaf1 100644 > > > --- a/drivers/media/i2c/ov5645.c > > > +++ b/drivers/media/i2c/ov5645.c > > > @@ -995,14 +995,11 @@ static int ov5645_s_stream(struct v4l2_subdev *subdev, int enable) > > > if (ret < 0) > > > goto err_rpm_put; > > > } else { > > > - ret = ov5645_write_reg(ov5645, OV5645_IO_MIPI_CTRL00, 0x40); > > > - if (ret < 0) > > > - return ret; > > > + ov5645_write_reg(ov5645, OV5645_IO_MIPI_CTRL00, 0x40); > > > + > > > + ov5645_write_reg(ov5645, OV5645_SYSTEM_CTRL0, > > > + OV5645_SYSTEM_CTRL0_STOP); > > > > > > - ret = ov5645_write_reg(ov5645, OV5645_SYSTEM_CTRL0, > > > - OV5645_SYSTEM_CTRL0_STOP); > > > - if (ret < 0) > > > - return ret; > > > pm_runtime_put(ov5645->dev); > > > } > > >
Hi Laurent, On Sun, Oct 16, 2022 at 02:23:13AM +0300, Laurent Pinchart wrote: > Hi Sakari, > > On Sat, Oct 15, 2022 at 09:35:12PM +0000, Sakari Ailus wrote: > > On Sat, Oct 15, 2022 at 09:25:37AM +0300, Laurent Pinchart wrote: > > > On Fri, Oct 14, 2022 at 07:34:58PM +0100, Prabhakar wrote: > > > > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > > > > > > > > Always return zero while stopping the stream as the caller will ignore the > > > > return value. > > > > > > > > This patch drops checking the return value of ov5645_write_reg() and > > > > continues further in the code path while stopping stream. The user anyway > > > > gets an error message in case ov5645_write_reg() fails. > > > > > > Continuing all the way to pm_runtime_put() is fine, but I don't think > > > the function should return 0. It's not up to the driver to decide if a > > > failure would be useful to signal to the caller or not. > > > > If the function returns an error when disabling streaming, what is the > > expected power state of the device after this? > > That's up to us to decide :-) > > > The contract between the caller and the callee is that the state is not > > changed if there is an error. > > For most APIs, but that's not universal. > > > This is a special case as very few callers > > check the return value for streamoff operation and those that do generally > > just print something. I've never seen a caller trying to prevent streaming > > off in this case, for instance. > > I think the stream off call should proceed and try to power off the > device even if an error occurs along the way, i.e. it shouldn't return > upon the first detected error. > > > Of course we could document that streaming off always counts as succeeded > > (e.g. decreasing device's runtime PM usage_count) while it could return an > > informational error code. But I wonder if anyone would ever benefit from > > that somehow. :-) > > I think it could be useful to propagate errors up to inform the user > that something wrong happened. That would involve fixing lots of drivers > along the call chain though, so there's no urgency for the ov5645 to do > so, but isn't it better to propagate the error code instead of hiding > the issue ? I also don't think hiding the issue would be the best thing to do, but that wouldn't likely be a big problem either. How about printing a warning in the wrapper while returning zero to the original caller? This would keep the API intact while still leaving a trace on something failing. Of course the driver is also free to print whatever messages it likes.
Hi Sakari, On Sun, Oct 16, 2022 at 08:19:40PM +0000, Sakari Ailus wrote: > On Sun, Oct 16, 2022 at 02:23:13AM +0300, Laurent Pinchart wrote: > > On Sat, Oct 15, 2022 at 09:35:12PM +0000, Sakari Ailus wrote: > > > On Sat, Oct 15, 2022 at 09:25:37AM +0300, Laurent Pinchart wrote: > > > > On Fri, Oct 14, 2022 at 07:34:58PM +0100, Prabhakar wrote: > > > > > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > > > > > > > > > > Always return zero while stopping the stream as the caller will ignore the > > > > > return value. > > > > > > > > > > This patch drops checking the return value of ov5645_write_reg() and > > > > > continues further in the code path while stopping stream. The user anyway > > > > > gets an error message in case ov5645_write_reg() fails. > > > > > > > > Continuing all the way to pm_runtime_put() is fine, but I don't think > > > > the function should return 0. It's not up to the driver to decide if a > > > > failure would be useful to signal to the caller or not. > > > > > > If the function returns an error when disabling streaming, what is the > > > expected power state of the device after this? > > > > That's up to us to decide :-) > > > > > The contract between the caller and the callee is that the state is not > > > changed if there is an error. > > > > For most APIs, but that's not universal. > > > > > This is a special case as very few callers > > > check the return value for streamoff operation and those that do generally > > > just print something. I've never seen a caller trying to prevent streaming > > > off in this case, for instance. > > > > I think the stream off call should proceed and try to power off the > > device even if an error occurs along the way, i.e. it shouldn't return > > upon the first detected error. > > > > > Of course we could document that streaming off always counts as succeeded > > > (e.g. decreasing device's runtime PM usage_count) while it could return an > > > informational error code. But I wonder if anyone would ever benefit from > > > that somehow. :-) > > > > I think it could be useful to propagate errors up to inform the user > > that something wrong happened. That would involve fixing lots of drivers > > along the call chain though, so there's no urgency for the ov5645 to do > > so, but isn't it better to propagate the error code instead of hiding > > the issue ? > > I also don't think hiding the issue would be the best thing to do, but that > wouldn't likely be a big problem either. > > How about printing a warning in the wrapper while returning zero to the > original caller? This would keep the API intact while still leaving a trace > on something failing. Of course the driver is also free to print whatever > messages it likes. While I think error propagation could be more useful in the long run, printing a message in the wrapper is a good idea. I like centralized error handling, it has a tendency to go wrong when left to individual drivers.
On Mon, Oct 17, 2022 at 12:03:17AM +0300, Laurent Pinchart wrote: > Hi Sakari, > > On Sun, Oct 16, 2022 at 08:19:40PM +0000, Sakari Ailus wrote: > > On Sun, Oct 16, 2022 at 02:23:13AM +0300, Laurent Pinchart wrote: > > > On Sat, Oct 15, 2022 at 09:35:12PM +0000, Sakari Ailus wrote: > > > > On Sat, Oct 15, 2022 at 09:25:37AM +0300, Laurent Pinchart wrote: > > > > > On Fri, Oct 14, 2022 at 07:34:58PM +0100, Prabhakar wrote: > > > > > > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > > > > > > > > > > > > Always return zero while stopping the stream as the caller will ignore the > > > > > > return value. > > > > > > > > > > > > This patch drops checking the return value of ov5645_write_reg() and > > > > > > continues further in the code path while stopping stream. The user anyway > > > > > > gets an error message in case ov5645_write_reg() fails. > > > > > > > > > > Continuing all the way to pm_runtime_put() is fine, but I don't think > > > > > the function should return 0. It's not up to the driver to decide if a > > > > > failure would be useful to signal to the caller or not. > > > > > > > > If the function returns an error when disabling streaming, what is the > > > > expected power state of the device after this? > > > > > > That's up to us to decide :-) > > > > > > > The contract between the caller and the callee is that the state is not > > > > changed if there is an error. > > > > > > For most APIs, but that's not universal. > > > > > > > This is a special case as very few callers > > > > check the return value for streamoff operation and those that do generally > > > > just print something. I've never seen a caller trying to prevent streaming > > > > off in this case, for instance. > > > > > > I think the stream off call should proceed and try to power off the > > > device even if an error occurs along the way, i.e. it shouldn't return > > > upon the first detected error. > > > > > > > Of course we could document that streaming off always counts as succeeded > > > > (e.g. decreasing device's runtime PM usage_count) while it could return an > > > > informational error code. But I wonder if anyone would ever benefit from > > > > that somehow. :-) > > > > > > I think it could be useful to propagate errors up to inform the user > > > that something wrong happened. That would involve fixing lots of drivers > > > along the call chain though, so there's no urgency for the ov5645 to do > > > so, but isn't it better to propagate the error code instead of hiding > > > the issue ? > > > > I also don't think hiding the issue would be the best thing to do, but that > > wouldn't likely be a big problem either. > > > > How about printing a warning in the wrapper while returning zero to the > > original caller? This would keep the API intact while still leaving a trace > > on something failing. Of course the driver is also free to print whatever > > messages it likes. > > While I think error propagation could be more useful in the long run, > printing a message in the wrapper is a good idea. I like centralized > error handling, it has a tendency to go wrong when left to individual > drivers. I can send a patch...
Hi Sakari, On Mon, Oct 17, 2022 at 8:12 AM Sakari Ailus <sakari.ailus@linux.intel.com> wrote: > > On Mon, Oct 17, 2022 at 12:03:17AM +0300, Laurent Pinchart wrote: > > Hi Sakari, > > > > On Sun, Oct 16, 2022 at 08:19:40PM +0000, Sakari Ailus wrote: > > > On Sun, Oct 16, 2022 at 02:23:13AM +0300, Laurent Pinchart wrote: > > > > On Sat, Oct 15, 2022 at 09:35:12PM +0000, Sakari Ailus wrote: > > > > > On Sat, Oct 15, 2022 at 09:25:37AM +0300, Laurent Pinchart wrote: > > > > > > On Fri, Oct 14, 2022 at 07:34:58PM +0100, Prabhakar wrote: > > > > > > > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > > > > > > > > > > > > > > Always return zero while stopping the stream as the caller will ignore the > > > > > > > return value. > > > > > > > > > > > > > > This patch drops checking the return value of ov5645_write_reg() and > > > > > > > continues further in the code path while stopping stream. The user anyway > > > > > > > gets an error message in case ov5645_write_reg() fails. > > > > > > > > > > > > Continuing all the way to pm_runtime_put() is fine, but I don't think > > > > > > the function should return 0. It's not up to the driver to decide if a > > > > > > failure would be useful to signal to the caller or not. > > > > > > > > > > If the function returns an error when disabling streaming, what is the > > > > > expected power state of the device after this? > > > > > > > > That's up to us to decide :-) > > > > > > > > > The contract between the caller and the callee is that the state is not > > > > > changed if there is an error. > > > > > > > > For most APIs, but that's not universal. > > > > > > > > > This is a special case as very few callers > > > > > check the return value for streamoff operation and those that do generally > > > > > just print something. I've never seen a caller trying to prevent streaming > > > > > off in this case, for instance. > > > > > > > > I think the stream off call should proceed and try to power off the > > > > device even if an error occurs along the way, i.e. it shouldn't return > > > > upon the first detected error. > > > > > > > > > Of course we could document that streaming off always counts as succeeded > > > > > (e.g. decreasing device's runtime PM usage_count) while it could return an > > > > > informational error code. But I wonder if anyone would ever benefit from > > > > > that somehow. :-) > > > > > > > > I think it could be useful to propagate errors up to inform the user > > > > that something wrong happened. That would involve fixing lots of drivers > > > > along the call chain though, so there's no urgency for the ov5645 to do > > > > so, but isn't it better to propagate the error code instead of hiding > > > > the issue ? > > > > > > I also don't think hiding the issue would be the best thing to do, but that > > > wouldn't likely be a big problem either. > > > > > > How about printing a warning in the wrapper while returning zero to the > > > original caller? This would keep the API intact while still leaving a trace > > > on something failing. Of course the driver is also free to print whatever > > > messages it likes. > > > > While I think error propagation could be more useful in the long run, > > printing a message in the wrapper is a good idea. I like centralized > > error handling, it has a tendency to go wrong when left to individual > > drivers. > > I can send a patch... > To conclude, for v3 I'll continue down the code path upon error and then report back the error? Cheers, Prabhakar
diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c index a0b9d0c43b78..b3825294aaf1 100644 --- a/drivers/media/i2c/ov5645.c +++ b/drivers/media/i2c/ov5645.c @@ -995,14 +995,11 @@ static int ov5645_s_stream(struct v4l2_subdev *subdev, int enable) if (ret < 0) goto err_rpm_put; } else { - ret = ov5645_write_reg(ov5645, OV5645_IO_MIPI_CTRL00, 0x40); - if (ret < 0) - return ret; + ov5645_write_reg(ov5645, OV5645_IO_MIPI_CTRL00, 0x40); + + ov5645_write_reg(ov5645, OV5645_SYSTEM_CTRL0, + OV5645_SYSTEM_CTRL0_STOP); - ret = ov5645_write_reg(ov5645, OV5645_SYSTEM_CTRL0, - OV5645_SYSTEM_CTRL0_STOP); - if (ret < 0) - return ret; pm_runtime_put(ov5645->dev); }