Re: [PATCH 4/4] btrfs: sysfs, add devid/dev_state kobject and attribute

David Sterba
2019-12-05T14:10:32Z

On Thu, Dec 05, 2019 at 07:27:06PM +0800, Anand Jain wrote:
> +static void btrfs_dev_state_to_str(struct btrfs_device *device, char *dev_state_str, size_t n)
> +{
> + int state;
> + const char *btrfs_dev_states[] = { "WRITEABLE", "IN_FS_METADATA",
> + "MISSING", "REPLACE_TGT", "FLUSHING"
> + };
> +
> + n = n - strlen(dev_state_str) - 1;
> +
> + for (state = 0; state < ARRAY_SIZE(btrfs_dev_states); state++) {
> + if (test_bit(state, &device->dev_state)) {
> + if (strlen(dev_state_str))
> + strncat(dev_state_str, " ", n);
> + strncat(dev_state_str, btrfs_dev_states[state], n);
> + }
> + }
> + strncat(dev_state_str, "\n", n);

Please use the snprintf way as in supported_checksums_show and not the
str* functions.