Re: [PATCH v13 3/4] PCI/DOE: Expose the DOE features via sysfs

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

 



> @@ -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






[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux