All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kishon Vijay Abraham I <kishon@ti.com>
To: u-boot@lists.denx.de
Subject: [PATCH v3 03/20] drivers: reset: Handle gracefully NULL pointers
Date: Thu, 6 May 2021 18:39:25 +0530	[thread overview]
Message-ID: <732d26e0-abdd-7f8f-7071-8f0d29b3102f@ti.com> (raw)
In-Reply-To: <CAPnjgZ0kQNsfD59DAHjv72pkBaGVTzaw9GL5=SJp07jMRBB0PA@mail.gmail.com>

Hi Simon,

On 06/05/21 5:07 am, Simon Glass wrote:
> Hi Kishon,
> 
> On Tue, 4 May 2021 at 21:25, Kishon Vijay Abraham I <kishon@ti.com> wrote:
>>
>> Hi Simon,
>>
>> On 04/05/21 10:28 pm, Simon Glass wrote:
>>> Hi Kishon,
>>>
>>> On Tue, 4 May 2021 at 04:42, Kishon Vijay Abraham I <kishon@ti.com> wrote:
>>>>
>>>> The reset framework provides devm_reset_control_get_optional()
>>>> which can return NULL (not an error case). So all the other reset_ops
>>>> should handle NULL gracefully. Prepare the way for a managed reset
>>>> API by handling NULL pointers without crashing nor failing.
>>>>
>>>> Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
>>>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>>>> ---
>>>>  drivers/reset/reset-uclass.c | 35 ++++++++++++++++++++++++++++++-----
>>>>  1 file changed, 30 insertions(+), 5 deletions(-)
>>>
>>> I am still not a fan of this. There is no way to know whether the
>>> reset API call actually did anything. Normally we return -EINVAL or
>>> something like that when the value is invalid (e.g. see GPIO uclass).
>>
>> The reset modification is more in-line with how clk uclass is designed.
>>
>> There every API first checks if the clock is valid and returns 0 (will
>> be the case for optional clocks)
>>        if (!clk_valid(clk))
>>                 return 0;
>>
>> If you don't prefer this approach, I'll drop this patch and handle it
>> appropriately in the client driver (serdes driver). Please let me know.
> 
> Yes I see that with clk. IMO the return code is incorrect there also,
> since it should be -ENOENT or something like that, to indicate that
> there is actually no clock.
> 
> The clk.h header gives no indication that it accepts a NULL clock. So
> here is what I think:
> 
> 1. Update clk_valid() to require clk to be a valid pointer, so it is
> considered invalid only if clk-dev.

So for API's like clk_enable(), clk_disable(), should it return 0 or
-ENOENT; i.e if clk is valid and clk->dev is NULL?
> 
> 2. Update the reset 'managed API' to return an empty reset record
> instead of NULL.

Okay, something like below?

--- a/drivers/reset/reset-uclass.c
+++ b/drivers/reset/reset-uclass.c
@@ -326,9 +326,6 @@ struct reset_ctl
*devm_reset_control_get_optional(struct udevice *dev,
 {
        struct reset_ctl *r = devm_reset_control_get(dev, id);

-       if (IS_ERR(r))
-               return NULL;
-
        return r;
 }

The only thing to note here is _get_optional() is a wrapper to _get()
with no modification.
> 
> 3. Your problem goes away, and (I think) we are still compatible with
> the linux API.
> 
>>
>>>
>>> The function you mention says:  * Returns a struct reset_ctl or a
>>> dummy reset controller if it failed.
>>>
>>> But it does not appear to do that?
>>
>> Right, looks like it's incorrect from when the patch was actually
>> introduced. It was returning "NULL" for optional resets.
>>
>> commit 139e4a1cbe60de96d4febbc6db5882929801ca46
>> Author: Jean-Jacques Hiblot <jjhiblot@ti.com>
>> Date:   Wed Sep 9 15:37:03 2020 +0530
>>
>>     drivers: reset: Add a managed API to get reset controllers from the DT
> 
> OK. So what should it be?

I meant the comment in header is incorrect since it was returning NULL
if it failed.

Thanks,
Kishon

  reply	other threads:[~2021-05-06 13:09 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-04 10:41 [PATCH v3 00/20] TI/Cadence: Add Sierra/Torrent SERDES driver Kishon Vijay Abraham I
2021-05-04 10:41 ` [PATCH v3 01/20] dm: core: Add helper to compare node names Kishon Vijay Abraham I
2021-05-04 16:58   ` Simon Glass
2021-05-04 10:41 ` [PATCH v3 02/20] dm: test: Add test case to check node name ignoring unit address Kishon Vijay Abraham I
2021-05-04 10:41 ` [PATCH v3 03/20] drivers: reset: Handle gracefully NULL pointers Kishon Vijay Abraham I
2021-05-04 16:58   ` Simon Glass
2021-05-05  4:25     ` Kishon Vijay Abraham I
2021-05-05 23:37       ` Simon Glass
2021-05-06 13:09         ` Kishon Vijay Abraham I [this message]
2021-05-06 15:06           ` Simon Glass
2021-05-04 10:41 ` [PATCH v3 04/20] dt-bindings: phy: Add definitions for additional phy types Kishon Vijay Abraham I
2021-05-04 10:41 ` [PATCH v3 05/20] dt-bindings: phy: Add defines for AM64 SERDES Wrapper Kishon Vijay Abraham I
2021-05-04 10:41 ` [PATCH v3 06/20] dt-bindings: phy: cadence-torrent: Add defines for refclk driver Kishon Vijay Abraham I
2021-05-04 10:41 ` [PATCH v3 07/20] dt-bindings: ti-serdes-mux: Add defines for AM64 SoC Kishon Vijay Abraham I
2021-05-04 10:41 ` [PATCH v3 08/20] phy: cadence: Add driver for Sierra PHY Kishon Vijay Abraham I
2021-05-04 10:41 ` [PATCH v3 09/20] phy: cadence: Add driver for Torrent SERDES Kishon Vijay Abraham I
2021-05-04 10:41 ` [PATCH v3 10/20] phy: ti: j721e-wiz: Add support for WIZ module present in TI J721E SoC Kishon Vijay Abraham I
2021-05-04 10:41 ` [PATCH v3 11/20] usb: cdns3: cdns3-ti: Fix clk_get_by_name() to get the correct name Kishon Vijay Abraham I
2021-05-04 10:41 ` [PATCH v3 12/20] board: ti: j721e: Add support for probing and configuring Torrent serdes on J7200 Kishon Vijay Abraham I
2021-05-04 10:41 ` [PATCH v3 13/20] ARM: dts: k3-j721e: Add the entries required for USB3 support on USB0 Kishon Vijay Abraham I
2021-05-07 17:14   ` Tom Rini
2021-07-09 14:06     ` Kishon Vijay Abraham I
2021-07-09 14:16       ` Tom Rini
2021-05-04 10:41 ` [PATCH v3 14/20] arm: dts: k3-j7200-main: Add DT node for torrent serdes Kishon Vijay Abraham I
2021-05-04 10:41 ` [PATCH v3 15/20] arm: dts: k3-j7200-common-proc-board: Enable SERDES DT Kishon Vijay Abraham I
2021-05-04 10:41 ` [PATCH v3 16/20] arm: dts: k3-j7200-common-proc-board-u-boot: Add u-boot tags for torrent serdes Kishon Vijay Abraham I
2021-05-04 10:41 ` [PATCH v3 17/20] configs: j721e_evm_a72: Enable the drivers required for the USB3 support Kishon Vijay Abraham I
2021-05-04 10:41 ` [PATCH v3 18/20] configs: j7200_evm_a72_defconfig: Add config for torrent serdes and common clock framework Kishon Vijay Abraham I
2021-05-04 10:41 ` [PATCH v3 19/20] env: ti: j721e-evm: Add env variable to power on & reset QSGMII PHY in J7200 EVM Kishon Vijay Abraham I
2021-05-07 17:14   ` Tom Rini
2021-05-11 13:58     ` Kishon Vijay Abraham I
2021-05-11 14:33       ` Tom Rini
2021-07-09 14:32         ` Kishon Vijay Abraham I
2021-07-09 14:36           ` Tom Rini
2021-05-04 10:41 ` [PATCH v3 20/20] configs: j7200_evm_a72: Enhance bootcmd to configure ethernet PHY Kishon Vijay Abraham I
2021-05-07 17:16 ` [PATCH v3 00/20] TI/Cadence: Add Sierra/Torrent SERDES driver Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=732d26e0-abdd-7f8f-7071-8f0d29b3102f@ti.com \
    --to=kishon@ti.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.