Re: [PATCH bpf-next 1/9] libbpf: generalize libbpf externs support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jun 18, 2020 at 12:38 AM Hao Luo <haoluo@xxxxxxxxxx> wrote:
>
> On Wed, Jun 17, 2020 at 9:21 AM Andrii Nakryiko <andriin@xxxxxx> wrote:
> >
> > Switch existing Kconfig externs to be just one of few possible kinds of more
> > generic externs. This refactoring is in preparation for ksymbol extern
> > support, added in the follow up patch. There are no functional changes
> > intended.
> >
> > Signed-off-by: Andrii Nakryiko <andriin@xxxxxx>
> > ---
>
> [...]
>
> > @@ -5572,30 +5635,33 @@ static int bpf_object__resolve_externs(struct bpf_object *obj,
> >  {
> >         bool need_config = false;
> >         struct extern_desc *ext;
> > +       void *kcfg_data;
> >         int err, i;
> > -       void *data;
> >
> >         if (obj->nr_extern == 0)
> >                 return 0;
> >
> > -       data = obj->maps[obj->kconfig_map_idx].mmaped;
> > +       if (obj->kconfig_map_idx >= 0)
> > +               kcfg_data = obj->maps[obj->kconfig_map_idx].mmaped;
> >
> >         for (i = 0; i < obj->nr_extern; i++) {
> >                 ext = &obj->externs[i];
> >
> > -               if (strcmp(ext->name, "LINUX_KERNEL_VERSION") == 0) {
> > -                       void *ext_val = data + ext->data_off;
> > +               if (ext->type == EXT_KCFG &&
> > +                   strcmp(ext->name, "LINUX_KERNEL_VERSION") == 0) {
> > +                       void *ext_val = kcfg_data + ext->kcfg.data_off;
> >                         __u32 kver = get_kernel_version();
> >
> >                         if (!kver) {
> >                                 pr_warn("failed to get kernel version\n");
> >                                 return -EINVAL;
> >                         }
> > -                       err = set_ext_value_num(ext, ext_val, kver);
> > +                       err = set_kcfg_value_num(ext, ext_val, kver);
> >                         if (err)
> >                                 return err;
> > -                       pr_debug("extern %s=0x%x\n", ext->name, kver);
> > -               } else if (strncmp(ext->name, "CONFIG_", 7) == 0) {
> > +                       pr_debug("extern (kcfg) %s=0x%x\n", ext->name, kver);
> > +               } else if (ext->type == EXT_KCFG &&
> > +                          strncmp(ext->name, "CONFIG_", 7) == 0) {
> >                         need_config = true;
> >                 } else {
> >                         pr_warn("unrecognized extern '%s'\n", ext->name);
>
> Ah, we need to initialize kcfg_data, otherwise the compiler will give
> a warning on potentially uninitialized data.

yep, good catch



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux