Hello Philippe,

On Friday 19 of January 2018 13:38:11 Philippe Mathieu-Daudé wrote:
> On 01/14/2018 05:14 PM, p...@cmp.felk.cvut.cz wrote:
> > From: Pavel Pisa <p...@cmp.felk.cvut.cz>
> >
> > +extern int (*can_bus_connect_to_host_variant)(CanBusState *bus,
> > +                                              const char *name);
>
> Isn't extern (*func) an anti-pattern?
> One might be tempted to call it without checking it is non-NULL...
>
> Please declare it as a function, and using a static pointer, i.e.:
>
> typedef int (*can_bus_connect_to_host_variant_t)(CanBusState *bus,
>                                        const char *name);
>
>
> static can_bus_connect_to_host_variant_t
> can_bus_connect_to_host_variant_handler;
>
> void
> set_can_bus_connect_to_host_variant(can_bus_connect_to_host_variant_t
> handler)
> {
>     can_bus_connect_to_host_variant_handler = handler;
> }
>
> int can_bus_connect_to_host_variant(CanBusState *bus,
>                           const char *name)
> {
>     if (!can_bus_connect_to_host_variant_handler) {
>         return ERROR;
>     }
>     return can_bus_connect_to_host_variant_handler(bus, name);
> }


Yes, that has been my initial idea but then I need
some way how to setup variant from can_socketcan.c
when it is linked in

Something like

static void __attribute__((constructor)) can_socketcan_setup_variant(void)
{

}

or

module_init()

or

in can_socketcan.c or have there some QOM object which
type initialization setups pointer early before
individual instances of kvaser_pci

Thanks for suggestion in advance,

Pavel


Reply via email to