Message ID | 20221014183459.181567-5-prabhakar.mahadev-lad.rj@bp.renesas.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Sakari Ailus |
Headers |
Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from <linux-media-owner@vger.kernel.org>) id 1ojPX9-00Azlz-5t; Fri, 14 Oct 2022 18:35:47 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230219AbiJNSfk (ORCPT <rfc822;mkrufky@linuxtv.org> + 1 other); Fri, 14 Oct 2022 14:35:40 -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-media@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-Google-Smtp-Source: AMsMyM7Hlq/qoUuIN7LZWt5FzuxUS5Vip9VOqXeP9bjmE6fswYv2HHk/IN4q6q5SaiDJTqoeH9XUgg== 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-media.vger.kernel.org> X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,FREEMAIL_FORGED_FROMDOMAIN=0.001,FREEMAIL_FROM=0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no |
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); }