Skip to content

Commit b57e43b

Browse files
dulibo1xiaoxiang781216
authored andcommitted
clk:fix some issues when use rpmsg clk
1.check the rpmsg name when clk_register. 2.clk_get rpmsg clk print error: clk/clk.c:1231:3: runtime error: null pointer passed as argument 2, which is declared to never be null 3.fix some function miss keyword FAR. 4.clk_disable_unused may disable rpmsg clk which disable the clk that maybe used by others Signed-off-by: dulibo1 <[email protected]>
1 parent 13ee3f8 commit b57e43b

File tree

4 files changed

+75
-53
lines changed

4 files changed

+75
-53
lines changed

drivers/clk/clk.c

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ static struct clk_s *__clk_lookup(FAR const char *name,
8585
static int __clk_register(FAR struct clk_s *clk);
8686

8787
static void clk_disable_unused_subtree(FAR struct clk_s *clk);
88+
static FAR struct clk_s *clk_lookup(FAR const char *name);
8889

8990
/* File system methods */
9091

@@ -729,6 +730,11 @@ static int __clk_register(FAR struct clk_s *clk)
729730
return -EINVAL;
730731
}
731732

733+
if (clk_lookup(clk->name))
734+
{
735+
return -EEXIST;
736+
}
737+
732738
if (clk->ops->set_rate &&
733739
!((clk->ops->round_rate || clk->ops->determine_rate) &&
734740
clk->ops->recalc_rate))
@@ -830,6 +836,36 @@ static void clk_disable_unused_subtree(FAR struct clk_s *clk)
830836
}
831837
}
832838

839+
static FAR struct clk_s *clk_lookup(FAR const char *name)
840+
{
841+
FAR struct clk_s *root_clk = NULL;
842+
FAR struct clk_s *ret = NULL;
843+
irqstate_t flags;
844+
845+
flags = clk_list_lock();
846+
list_for_every_entry(&g_clk_root_list, root_clk, struct clk_s, node)
847+
{
848+
ret = __clk_lookup(name, root_clk);
849+
if (ret)
850+
{
851+
goto out;
852+
}
853+
}
854+
855+
list_for_every_entry(&g_clk_orphan_list, root_clk, struct clk_s, node)
856+
{
857+
ret = __clk_lookup(name, root_clk);
858+
if (ret)
859+
{
860+
goto out;
861+
}
862+
}
863+
864+
out:
865+
clk_list_unlock(flags);
866+
return ret;
867+
}
868+
833869
/****************************************************************************
834870
* Public Functions
835871
****************************************************************************/
@@ -1004,46 +1040,23 @@ int clk_is_enabled(FAR struct clk_s *clk)
10041040

10051041
FAR struct clk_s *clk_get(FAR const char *name)
10061042
{
1007-
FAR struct clk_s *root_clk = NULL;
1008-
FAR struct clk_s *ret = NULL;
1009-
irqstate_t flags;
1043+
FAR struct clk_s *clk;
10101044

10111045
if (!name)
10121046
{
10131047
return NULL;
10141048
}
10151049

1016-
flags = clk_list_lock();
1017-
1018-
list_for_every_entry(&g_clk_root_list, root_clk, struct clk_s, node)
1019-
{
1020-
ret = __clk_lookup(name, root_clk);
1021-
if (ret)
1022-
{
1023-
goto out;
1024-
}
1025-
}
1026-
1027-
list_for_every_entry(&g_clk_orphan_list, root_clk, struct clk_s, node)
1028-
{
1029-
ret = __clk_lookup(name, root_clk);
1030-
if (ret)
1031-
{
1032-
goto out;
1033-
}
1034-
}
1035-
1036-
out:
1037-
clk_list_unlock(flags);
1050+
clk = clk_lookup(name);
10381051

10391052
#ifdef CONFIG_CLK_RPMSG
1040-
if (ret == NULL)
1053+
if (clk == NULL)
10411054
{
1042-
ret = clk_register_rpmsg(name, CLK_GET_RATE_NOCACHE);
1055+
clk = clk_register_rpmsg(name, CLK_GET_RATE_NOCACHE);
10431056
}
10441057
#endif
10451058

1046-
return ret;
1059+
return clk;
10471060
}
10481061

10491062
int clk_set_parent(FAR struct clk_s *clk, FAR struct clk_s *parent)
@@ -1222,9 +1235,12 @@ FAR struct clk_s *clk_register(FAR const char *name,
12221235
clk->num_parents = num_parents;
12231236
clk->flags = flags;
12241237

1225-
clk->private_data = (char *)clk + off;
1226-
memcpy(clk->private_data, private_data, private_size);
1227-
off += private_size;
1238+
if (private_data)
1239+
{
1240+
clk->private_data = (char *)clk + off;
1241+
memcpy(clk->private_data, private_data, private_size);
1242+
off += private_size;
1243+
}
12281244

12291245
for (i = 0; i < num_parents; i++)
12301246
{

drivers/clk/clk_mux.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ static int clk_mux_set_parent(FAR struct clk_s *clk, uint8_t index)
8585

8686
static uint32_t
8787
clk_mux_determine_rate(FAR struct clk_s *clk, uint32_t rate,
88-
uint32_t *best_parent_rate,
89-
struct clk_s **best_parent_p)
88+
FAR uint32_t *best_parent_rate,
89+
FAR struct clk_s **best_parent_p)
9090
{
9191
FAR struct clk_mux_s *mux = to_clk_mux(clk);
9292
FAR struct clk_s *parent;
@@ -173,7 +173,7 @@ const struct clk_ops_s g_clk_mux_ro_ops =
173173
****************************************************************************/
174174

175175
FAR struct clk_s *clk_register_mux(FAR const char *name,
176-
const char * const *parent_names,
176+
FAR const char * const *parent_names,
177177
uint8_t num_parents,
178178
uint8_t flags, uint32_t reg,
179179
uint8_t shift, uint8_t width,

drivers/clk/clk_rpmsg.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct clk_rpmsg_server_s
7171
struct clk_rpmsg_s
7272
{
7373
FAR struct clk_s *clk;
74-
uint32_t count;
74+
bool enable;
7575
struct list_node node;
7676
};
7777

@@ -314,20 +314,22 @@ static int clk_rpmsg_enable_handler(FAR struct rpmsg_endpoint *ept,
314314
{
315315
FAR struct clk_rpmsg_enable_s *msg = data;
316316
FAR struct clk_rpmsg_s *clkrp = clk_rpmsg_get_clk(ept, msg->name);
317+
int ret = -ENOENT;
317318

318-
if (clkrp)
319+
if (clkrp && !clkrp->enable)
319320
{
320-
msg->header.result = clk_enable(clkrp->clk);
321-
if (!msg->header.result)
321+
ret = clk_enable(clkrp->clk);
322+
if (ret >= 0)
322323
{
323-
clkrp->count++;
324+
clkrp->enable = true;
324325
}
325326
}
326-
else
327+
else if (clkrp && clkrp->enable)
327328
{
328-
msg->header.result = -ENOENT;
329+
ret = 0;
329330
}
330331

332+
msg->header.result = ret;
331333
return rpmsg_send(ept, msg, sizeof(*msg));
332334
}
333335

@@ -337,18 +339,22 @@ static int clk_rpmsg_disable_handler(FAR struct rpmsg_endpoint *ept,
337339
{
338340
FAR struct clk_rpmsg_disable_s *msg = data;
339341
FAR struct clk_rpmsg_s *clkrp = clk_rpmsg_get_clk(ept, msg->name);
342+
int ret = -ENOENT;
340343

341-
if (clkrp)
344+
if (clkrp && clkrp->enable)
342345
{
343-
clk_disable(clkrp->clk);
344-
clkrp->count--;
345-
msg->header.result = 0;
346+
ret = clk_disable(clkrp->clk);
347+
if (ret >= 0)
348+
{
349+
clkrp->enable = false;
350+
}
346351
}
347-
else
352+
else if (clkrp && !clkrp->enable)
348353
{
349-
msg->header.result = -ENOENT;
354+
ret = 0;
350355
}
351356

357+
msg->header.result = ret;
352358
return rpmsg_send(ept, msg, sizeof(*msg));
353359
}
354360

@@ -457,7 +463,7 @@ static int clk_rpmsg_isenabled_handler(FAR struct rpmsg_endpoint *ept,
457463

458464
if (clkrp)
459465
{
460-
msg->header.result = clk_is_enabled(clkrp->clk);
466+
msg->header.result = clkrp->enable;
461467
}
462468
else
463469
{
@@ -536,7 +542,7 @@ static void clk_rpmsg_server_unbind(FAR struct rpmsg_endpoint *ept)
536542
list_for_every_entry_safe(&priv->clk_list, clkrp, clkrp_tmp,
537543
struct clk_rpmsg_s, node)
538544
{
539-
while (clkrp->count--)
545+
if (clkrp->enable)
540546
{
541547
clk_disable(clkrp->clk);
542548
}

include/nuttx/clk/clk_provider.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ struct clk_ops_s
114114
CODE int (*is_enabled)(FAR struct clk_s *clk);
115115
CODE uint32_t (*recalc_rate)(FAR struct clk_s *clk, uint32_t parent_rate);
116116
CODE uint32_t (*round_rate)(FAR struct clk_s *clk,
117-
uint32_t rate, uint32_t *parent_rate);
117+
uint32_t rate, FAR uint32_t *parent_rate);
118118
CODE uint32_t (*determine_rate)(FAR struct clk_s *clk, uint32_t rate,
119-
uint32_t *best_parent_rate,
120-
struct clk_s **best_parent_clk);
119+
FAR uint32_t *best_parent_rate,
120+
FAR struct clk_s **best_parent_clk);
121121
CODE int (*set_parent)(FAR struct clk_s *clk, uint8_t index);
122122
CODE uint8_t (*get_parent)(FAR struct clk_s *clk);
123123
CODE int (*set_rate)(FAR struct clk_s *clk, uint32_t rate,
@@ -243,7 +243,7 @@ FAR struct clk_s *clk_register_multiplier(FAR const char *name,
243243
uint8_t clk_multiplier_flags);
244244

245245
FAR struct clk_s *clk_register_mux(FAR const char *name,
246-
const char * const *parent_names,
246+
FAR const char * const *parent_names,
247247
uint8_t num_parents, uint8_t flags,
248248
uint32_t reg, uint8_t shift,
249249
uint8_t width, uint8_t clk_mux_flags);

0 commit comments

Comments
 (0)