Mostafa Zarghami
Mostafa Zarghami

Reputation: 25

How can i use a function in multiple drivers?

I want to call do_input_boost function in another driver but I couldn't find the way to call the function.

static void do_input_boost(struct kthread_work *work)
{
    unsigned int i, ret;
    struct cpu_sync *i_sync_info;

    /* Set the input_boost_min for all CPUs in the system */
    pr_debug("Setting input boost min for all CPUs\n");
    for_each_possible_cpu(i) {
        i_sync_info = &per_cpu(sync_info, i);
        i_sync_info->input_boost_min = i_sync_info->input_boost_freq;
    }

    queue_delayed_work(system_power_efficient_wq,
        &input_boost_rem, msecs_to_jiffies(input_boost_ms));
}

I also added EXPORT_SYMBOL(do_input_boost) but couldn't find the proper prototype definition for calling this function, like

do_input_boost();

EDIT: i added a hear and linked in target driver

#ifdef CONFIG_CPU_BOOST
extern void do_input_boost(void);
#else
extern void do_input_boost(void)
{
}
#endif

Upvotes: 1

Views: 169

Answers (1)

Gaurav
Gaurav

Reputation: 1600

IMO you'll have to remove static as it limits the visibility of this function to the current translational unit (provided the other driver is not in the same .c file).

Removing static will make that function global and from other .c files it will be accessible using extern declaration.

lets say that this function of ours do_input_boost is defined in a.c file and your driver is in b.c file (where you want to call that function), then:

in b.c you'll declare that function: extern void do_input_boost(struct kthread_work*); and then you can call that.

Upvotes: 1

Related Questions