Skip to contentSkip to conversation

ata/sata_mv: Remove conditional compilation of clk code

PATCH In review Andrew Lunn 4 participants 8 messages Apr 24, 2012 libata

lore
Share & tools
lore
#0 lore raw

PATCH v2 4/9 ata/sata_mv: Remove conditional compilation of clk code

Hi Viresh

Review

Quoted 13 lines

With addition of dummy clk_*() calls for non CONFIG_HAVE_CLK cases in clk.h, there is no need to have clk code enclosed in #ifdef CONFIG_HAVE_CLK, #endif macros.

...

(quoted diff) +0 -2
-#if defined(CONFIG_HAVE_CLK)
        hpriv->clk = clk_get(&pdev->dev, NULL);
        if (IS_ERR(hpriv->clk))
                dev_notice(&pdev->dev, "cannot get clkdev\n");
        else
                clk_enable(hpriv->clk);
-#endif

I don't think this change is correct. With the old semantics, it was:

If we have CLK support, we expect there to be a clock for sata_mv, and if there is no such clock, output a notice message, something is probably wrong, i expected there to be a clock.

The new semantics are:

We expect there to be a clock for sata_mv, and if there is no such clock, output a notice message, something is probably wrong, i expected there to be a clock.

We are going to see this notice message much more, when it is not expected.

Andrew

#1 lore raw
Quoted 1 line · Andrew Lunn

I don't think this change is correct. With the old semantics, it was:

Sorry. :(

Quoted 4 lines

If we have CLK support, we expect there to be a clock for sata_mv, and if there is no such clock, output a notice message, something is probably wrong, i expected there to be a clock.

Quoted 8 lines

The new semantics are:

We expect there to be a clock for sata_mv, and if there is no such clock, output a notice message, something is probably wrong, i expected there to be a clock.

We are going to see this notice message much more, when it is not expected.

So, the only problem is this message?
How do you suggest to tackle this now. Have #ifdef,#endif around this print?

Signature · 1 line
viresh
#2 lore raw
Quoted 15 lines · Viresh Kumar
Quoted 1 line · Andrew Lunn

I don't think this change is correct. With the old semantics, it was:

Sorry. :(

Quoted 10 lines

If we have CLK support, we expect there to be a clock for sata_mv, and if there is no such clock, output a notice message, something is probably wrong, i expected there to be a clock.

The new semantics are:

We expect there to be a clock for sata_mv, and if there is no such clock, output a notice message, something is probably wrong, i expected there to be a clock.

Quoted 5 lines
Quoted 2 lines

We are going to see this notice message much more, when it is not expected.

So, the only problem is this message?
How do you suggest to tackle this now. Have #ifdef,#endif around this print?

Well, adding #ifdef defeats the point of adding dummy implementations.

Maybe, rather than return -ENODEV, return -ENOTSUP.

IS_ERR() still returns true, so in most cases, no code needs changing. However, when you need to differentiate between, "clock does not exists" and "Dummy clock functions being used", you can tell the difference. mv_sata could look like:

        hpriv->clk = clk_get(&pdev->dev, NULL);
        if (IS_ERR(hpriv->clk))
	        if (PTR_ERR(hpriv->clk) == -ENODEV)
		        dev_notice(&pdev->dev, "cannot get clkdev\n");
        else
                clk_prepare_enable(hpriv->clk);

You would however, need to look at all uses of clk_get and see if any are looked for ENODEV, and not just IS_ERR(), and fix those....

Andrew

#3 lore raw
Quoted 39 lines · Andrew Lunn
Quoted 15 lines · Viresh Kumar
Quoted 1 line · Andrew Lunn

I don't think this change is correct. With the old semantics, it was:

Sorry. :(

Quoted 10 lines

If we have CLK support, we expect there to be a clock for sata_mv, and if there is no such clock, output a notice message, something is probably wrong, i expected there to be a clock.

The new semantics are:

We expect there to be a clock for sata_mv, and if there is no such clock, output a notice message, something is probably wrong, i expected there to be a clock.

Quoted 5 lines
Quoted 2 lines

We are going to see this notice message much more, when it is not expected.

So, the only problem is this message?
How do you suggest to tackle this now. Have #ifdef,#endif around this print?

Well, adding #ifdef defeats the point of adding dummy implementations.

Maybe, rather than return -ENODEV, return -ENOTSUP.

IS_ERR() still returns true, so in most cases, no code needs changing. However, when you need to differentiate between, "clock does not exists" and "Dummy clock functions being used", you can tell the difference. mv_sata could look like:

        hpriv->clk = clk_get(&pdev->dev, NULL);
        if (IS_ERR(hpriv->clk))
	        if (PTR_ERR(hpriv->clk) == -ENODEV)
		        dev_notice(&pdev->dev, "cannot get clkdev\n");
        else
                clk_prepare_enable(hpriv->clk);
Quoted 2 lines

You would however, need to look at all uses of clk_get and see if any are looked for ENODEV, and not just IS_ERR(), and fix those....

Why bother?

If you don't have the clk API configured, you have no clocks to control. So, why not make clk_get() return NULL, and make the rest of the API calls do nothing? That's what you'll end up codifying in the drivers anyway.

#4 lore raw
Quoted 4 lines · Russell King - ARM Linux

If you don't have the clk API configured, you have no clocks to control. So, why not make clk_get() return NULL, and make the rest of the API calls do nothing? That's what you'll end up codifying in the drivers anyway.

Ok. We can return NULL from calls that return clk *. What about other routines that return integers. Like, clk_enable().

Is returning 0 correct? Which would mean we were able to enable clk, but actually we haven't.

Signature · 1 line
viresh
#5 lore raw
Quoted 11 lines · Viresh Kumar
Quoted 4 lines · Russell King - ARM Linux

If you don't have the clk API configured, you have no clocks to control. So, why not make clk_get() return NULL, and make the rest of the API calls do nothing? That's what you'll end up codifying in the drivers anyway.

Ok. We can return NULL from calls that return clk *. What about other routines that return integers. Like, clk_enable().

Is returning 0 correct? Which would mean we were able to enable clk, but actually we haven't.

Think about this case: if you don't have the means to control the clock inputs to a device (for example, you don't support the clk API on your CPU arch) then for the device to be functional, it must be supplied with all its necessary clocks. Therefore, the clock is already enabled. It makes sense for the clk API to stub-out to be completely transparent and non-error inducing to the driver.

The problem comes with clk_get_rate(). I'd suggest merely returning zero for that in this case. If the clock rate is really required by a driver, then the clk API would need to be enabled.

#6 lore raw
Quoted 10 lines · Russell King - ARM Linux

Think about this case: if you don't have the means to control the clock inputs to a device (for example, you don't support the clk API on your CPU arch) then for the device to be functional, it must be supplied with all its necessary clocks. Therefore, the clock is already enabled. It makes sense for the clk API to stub-out to be completely transparent and non-error inducing to the driver.

The problem comes with clk_get_rate(). I'd suggest merely returning zero for that in this case. If the clock rate is really required by a driver, then the clk API would need to be enabled.

Ok. Will do as suggested. Will include the patches i dropped earlier, where i removed macros for clk_*().

Signature · 1 line
viresh
#7 lore raw
In reply to Viresh Kumar

Hello.

Quoted 14 lines · Viresh Kumar
Quoted 1 line

I don't think this change is correct. With the old semantics, it was:

Sorry. :(

Quoted 9 lines

If we have CLK support, we expect there to be a clock for sata_mv, and if there is no such clock, output a notice message, something is probably wrong, i expected there to be a clock.

The new semantics are:

We expect there to be a clock for sata_mv, and if there is no such clock, output a notice message, something is probably wrong, i expected there to be a clock.

Quoted 5 lines
Quoted 2 lines

We are going to see this notice message much more, when it is not expected.

So, the only problem is this message?
How do you suggest to tackle this now. Have #ifdef,#endif around this print?

When there's no CONFIG_HAVE_CLK, if clk_get() returns NULL, not error,
there'll be no message.

WBR, Sergei