public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* Seeking advice on API return type inconsistency
@ 2025-08-11 15:24 Andrew Goodbody
  2025-08-11 16:36 ` Quentin Schulz
  0 siblings, 1 reply; 16+ messages in thread
From: Andrew Goodbody @ 2025-08-11 15:24 UTC (permalink / raw)
  To: u-boot@lists.denx.de, Tom Rini

Hi,

I was wondering what people's thoughts were on API return types. In 
particular there is this and other examples in include/clk-uclass.h

/**
  * get_rate() - Get current clock rate.
  * @clk:	The clock to query.
  *
  * This returns the current rate of a clock. If the clock is disabled, it
  * returns the rate at which the clock would run if it was enabled. The
  * following pseudo-code should hold::
  *
  *   disable(clk)
  *   rate = get_rate(clk)
  *   enable(clk)
  *   assert(get_rate(clk) == rate)
  *
  * Return:
  * * The rate of @clk
  * * -%ENOSYS if this function is not implemented for @clk
  * * -%ENOENT if @clk->id is invalid. Prefer using an assert instead, 
and doing
  *   this check in request().
  * * Another negative error value (such as %EIO or %ECOMM) if the rate 
could
  *   not be determined due to a bus error.
  */
ulong get_rate(struct clk *clk);


get_rate is declared as returning a ulong but the description says that 
it can return negative errors. A simple test of the return value for 
being less than 0 will always fail so errors can go undetected. Casting 
to a signed type seems less than ideal.

What is the best way to deal with this? Cast to a signed or update the 
API to be signed or...?

Andrew

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2025-10-15 15:59 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-11 15:24 Seeking advice on API return type inconsistency Andrew Goodbody
2025-08-11 16:36 ` Quentin Schulz
2025-08-12  9:17   ` Andrew Goodbody
2025-08-12 14:33     ` Tom Rini
2025-08-12 14:40       ` Heinrich Schuchardt
2025-08-12 14:46       ` Andrew Goodbody
2025-08-12 15:03         ` Tom Rini
2025-08-13 10:58           ` Andrew Goodbody
2025-08-13 11:41             ` Michal Suchánek
2025-08-13 15:40               ` Tom Rini
2025-08-13 16:34                 ` Andrew Goodbody
2025-10-15 14:22                 ` Andrew Goodbody
2025-10-15 15:53                   ` Andrew Goodbody
2025-10-15 15:57                     ` Tom Rini
2025-09-19 15:51               ` Simon Glass
2025-09-19 16:37                 ` Michal Suchánek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox