Re: [PATCH v13 3/4] PCI/DOE: Expose the DOE features via sysfs
From: Chaitanya Kulkarni
Date: Tue Jul 02 2024 - 07:57:57 EST
> @@ -707,6 +773,45 @@ void pci_doe_init(struct pci_dev *pdev)
> pci_doe_destroy_mb(doe_mb);
> }
> }
> +
> + if (doe_mb) {
> + xa_for_each(&doe_mb->feats, i, entry)
> + num_features++;
> +
> + sysfs_attrs = kcalloc(num_features + 1, sizeof(*sysfs_attrs), GFP_KERNEL);
> + if (!sysfs_attrs)
> + return;
> +
> + attrs = kcalloc(num_features, sizeof(*attrs), GFP_KERNEL);
> + if (!attrs) {
> + kfree(sysfs_attrs);
> + return;
> + }
> +
> + doe_mb->device_attrs = attrs;
> + doe_mb->sysfs_attrs = sysfs_attrs;
> +
> + xa_for_each(&doe_mb->feats, i, entry) {
> + sysfs_attr_init(&attrs[i].attr);
> +
> + vid = xa_to_value(entry) >> 8;
> + type = xa_to_value(entry) & 0xFF;
> +
> + attrs[i].attr.name = kasprintf(GFP_KERNEL, "%04lx:%02lx", vid, type);
> + if (!attrs[i].attr.name) {
> + pci_doe_sysfs_feature_remove(pdev, doe_mb);
> + return;
> + }
> + attrs[i].attr.mode = 0444;
> + attrs[i].show = pci_doe_sysfs_feature_show;
> +
> + sysfs_attrs[i] = &attrs[i].attr;
> + }
> +
> + sysfs_attrs[num_features] = NULL;
shouldn't sysfs_attrs[num_features] be already NULL since it's allocated
using kcalloc() ?
> +
> + pci_doe_sysfs_group.attrs = sysfs_attrs;
> + }
-ck