[PATCH V3 2/2] nvmem: add driver handling U-Boot environment variables
Rafał Miłecki
zajec5 at gmail.com
Wed Jun 15 11:30:12 PDT 2022
On 14.06.2022 08:45, Ahmad Fatoum wrote:
>> + if (err && !mtd_is_bitflip(err)) {
>> + dev_err(dev, "Failed to read from mtd: %d\n", err);
>
> Nitpick: %pe
My "err" variable in int, not a pointer (I don't use PTR_ERR()).
>> +static int u_boot_env_add_cells(struct u_boot_env *priv, uint8_t *buf,
>> + size_t data_offset, size_t data_len)
>> +{
>> + struct device *dev = priv->dev;
>> + char *data = buf + data_offset;
>> + char *var, *value, *eq;
>> + int idx;
>> +
>> + priv->ncells = 0;
>> + for (var = data; var < data + data_len && *var; var += strlen(var) + 1)
>> + priv->ncells++;
>> +
>> + priv->cells = devm_kcalloc(dev, priv->ncells, sizeof(*priv->cells), GFP_KERNEL);
>> + if (!priv->cells)
>> + return -ENOMEM;
>> +
>> + for (var = data, idx = 0;
>> + var < data + data_len && *var;
>> + var = value + strlen(value) + 1, idx++) {
>> + eq = strchr(var, '=');
>> + if (!eq)
>> + break;
>> + *eq = '\0';
>> + value = eq + 1;
>> +
>> + priv->cells[idx].name = devm_kstrdup(dev, var, GFP_KERNEL);
>> + if (!priv->cells[idx].name)
>> + return -ENOMEM;
>> + priv->cells[idx].offset = data_offset + value - data;
>> + priv->cells[idx].bytes = strlen(value);
>
> U-Boot environment can't hold binary values?
I believe it can't. In any case \0 is a always a separator.
>> + }
>> +
>> + if (WARN_ON(idx != priv->ncells))
>> + priv->ncells = idx;
>> +
>> + return 0;
>> +}
More information about the linux-mtd
mailing list