Hi Wang,
No, you do *not* normally need to use symbol_get(): you just
use the symbol like normal and the loader will make sure reference
counts are adjusted etc.
Here's an example of use, from my (completely untested) "make
mtd use symbol_get()" patch, which allows mtd to look for support for
a given command set at runtime (rather than forcing all command set
modules to be present to load at all):
================
typedef struct mtd_info *cfi_cmdset_fn_t(struct map_info *, int);
static struct mtd_info *unknown_cmdset(struct map_info *map, int primary)
{
struct cfi_private *cfi = map->fldrv_priv;
__u16 type = primary?cfi->cfiq->P_ID:cfi->cfiq->A_ID;
printk(KERN_NOTICE "Support for command set %04X not present\n",
type);
return NULL;
}
/* when we are built without module support, so we still link */
cfi_cmdset_fn_t cfi_cmdset_0001 __attribute__((weak, alias("unknown_cmdset")));
cfi_cmdset_fn_t cfi_cmdset_0002 __attribute__((weak, alias("unknown_cmdset")));
cfi_cmdset_fn_t cfi_cmdset_0003 __attribute__((weak, alias("unknown_cmdset")));
static inline struct mtd_info *cfi_cmdset_unknown(struct map_info *map,
int primary)
{
struct cfi_private *cfi = map->fldrv_priv;
__u16 type = primary?cfi->cfiq->P_ID:cfi->cfiq->A_ID;
cfi_cmdset_fn_t *probe_function = NULL;
switch (type) {
case 1:
probe_function = symbol_get(cfi_cmdset_0001);
break;
case 2:
probe_function = symbol_get(cfi_cmdset_0002);
break;
case 3:
probe_function = symbol_get(cfi_cmdset_0003);
break;
}
if (probe_function) {
struct mtd_info *mtd;
mtd = (*probe_function)(map, primary);
return mtd;
}
return unknown_cmdset(map, primary);
}
-- Anyone who quotes me in their sig is an idiot. -- Rusty Russell. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/