Prepare the way for a managed CLK API by handling NULL pointers without
crashing nor failing.
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
int clk_request(struct udevice *dev, struct clk *clk)
{
int clk_request(struct udevice *dev, struct clk *clk)
{
- const struct clk_ops *ops = clk_dev_ops(dev);
+ const struct clk_ops *ops;
debug("%s(dev=%p, clk=%p)\n", __func__, dev, clk);
debug("%s(dev=%p, clk=%p)\n", __func__, dev, clk);
+ if (!clk)
+ return 0;
+ ops = clk_dev_ops(dev);
int clk_free(struct clk *clk)
{
int clk_free(struct clk *clk)
{
- const struct clk_ops *ops = clk_dev_ops(clk->dev);
+ const struct clk_ops *ops;
debug("%s(clk=%p)\n", __func__, clk);
debug("%s(clk=%p)\n", __func__, clk);
+ if (!clk)
+ return 0;
+ ops = clk_dev_ops(clk->dev);
if (!ops->free)
return 0;
if (!ops->free)
return 0;
ulong clk_get_rate(struct clk *clk)
{
ulong clk_get_rate(struct clk *clk)
{
- const struct clk_ops *ops = clk_dev_ops(clk->dev);
+ const struct clk_ops *ops;
debug("%s(clk=%p)\n", __func__, clk);
debug("%s(clk=%p)\n", __func__, clk);
+ if (!clk)
+ return 0;
+ ops = clk_dev_ops(clk->dev);
if (!ops->get_rate)
return -ENOSYS;
if (!ops->get_rate)
return -ENOSYS;
struct clk *pclk;
debug("%s(clk=%p)\n", __func__, clk);
struct clk *pclk;
debug("%s(clk=%p)\n", __func__, clk);
+ if (!clk)
+ return NULL;
pdev = dev_get_parent(clk->dev);
pclk = dev_get_clk_ptr(pdev);
pdev = dev_get_parent(clk->dev);
pclk = dev_get_clk_ptr(pdev);
struct clk *pclk;
debug("%s(clk=%p)\n", __func__, clk);
struct clk *pclk;
debug("%s(clk=%p)\n", __func__, clk);
pclk = clk_get_parent(clk);
if (IS_ERR(pclk))
pclk = clk_get_parent(clk);
if (IS_ERR(pclk))
ulong clk_set_rate(struct clk *clk, ulong rate)
{
ulong clk_set_rate(struct clk *clk, ulong rate)
{
- const struct clk_ops *ops = clk_dev_ops(clk->dev);
+ const struct clk_ops *ops;
debug("%s(clk=%p, rate=%lu)\n", __func__, clk, rate);
debug("%s(clk=%p, rate=%lu)\n", __func__, clk, rate);
+ if (!clk)
+ return 0;
+ ops = clk_dev_ops(clk->dev);
if (!ops->set_rate)
return -ENOSYS;
if (!ops->set_rate)
return -ENOSYS;
int clk_set_parent(struct clk *clk, struct clk *parent)
{
int clk_set_parent(struct clk *clk, struct clk *parent)
{
- const struct clk_ops *ops = clk_dev_ops(clk->dev);
+ const struct clk_ops *ops;
debug("%s(clk=%p, parent=%p)\n", __func__, clk, parent);
debug("%s(clk=%p, parent=%p)\n", __func__, clk, parent);
+ if (!clk)
+ return 0;
+ ops = clk_dev_ops(clk->dev);
if (!ops->set_parent)
return -ENOSYS;
if (!ops->set_parent)
return -ENOSYS;
int clk_enable(struct clk *clk)
{
int clk_enable(struct clk *clk)
{
- const struct clk_ops *ops = clk_dev_ops(clk->dev);
+ const struct clk_ops *ops;
struct clk *clkp = NULL;
int ret;
debug("%s(clk=%p)\n", __func__, clk);
struct clk *clkp = NULL;
int ret;
debug("%s(clk=%p)\n", __func__, clk);
+ if (!clk)
+ return 0;
+ ops = clk_dev_ops(clk->dev);
if (CONFIG_IS_ENABLED(CLK_CCF)) {
/* Take id 0 as a non-valid clk, such as dummy */
if (CONFIG_IS_ENABLED(CLK_CCF)) {
/* Take id 0 as a non-valid clk, such as dummy */
int clk_disable(struct clk *clk)
{
int clk_disable(struct clk *clk)
{
- const struct clk_ops *ops = clk_dev_ops(clk->dev);
+ const struct clk_ops *ops;
struct clk *clkp = NULL;
int ret;
debug("%s(clk=%p)\n", __func__, clk);
struct clk *clkp = NULL;
int ret;
debug("%s(clk=%p)\n", __func__, clk);
+ if (!clk)
+ return 0;
+ ops = clk_dev_ops(clk->dev);
if (CONFIG_IS_ENABLED(CLK_CCF)) {
if (clk->id && !clk_get_by_id(clk->id, &clkp)) {
if (CONFIG_IS_ENABLED(CLK_CCF)) {
if (clk->id && !clk_get_by_id(clk->id, &clkp)) {
+ /* trivial case #2: on the clk pointer is NULL */
+ if (!p || !q)
+ return false;
+
/* same device, id and data */
if (p->dev == q->dev && p->id == q->id && p->data == q->data)
return true;
/* same device, id and data */
if (p->dev == q->dev && p->id == q->id && p->data == q->data)
return true;
*/
static inline bool clk_valid(struct clk *clk)
{
*/
static inline bool clk_valid(struct clk *clk)
{
+ return clk && !!clk->dev;