Commit ce93b5bd authored by Federico Vaga's avatar Federico Vaga

Merge branch '13-null-pointer-in-the-error-handling-process-of-add_eeprom' into 'master'

Resolve "NULL pointer in the error handling process of add_eeprom"

Closes #13

See merge request be-cem-edl/fec/hardware-modules/fmc!8
parents 92c324fc 72c86808
Pipeline #5120 failed
......@@ -12,7 +12,7 @@ endif
LINUXINCLUDE := -I$(src)/include -I$(src)/../../include -I$(src)/../../include/uapi $(LINUXINCLUDE)
ccflags-y += -DADDITIONAL_VERSIONS="$(SUBMODULE_VERSIONS-y)"
ccflags-y += -Werror
ccflags-y += -Werror -ggdb
ccflags-y += -I$(src)/../../include
obj-$(CONFIG_FMC) = fmc.o
......
......@@ -87,8 +87,9 @@ static void fmc_slot_release(struct device *dev)
struct fmc_slot *slot = to_fmc_slot(dev);
i2c_put_adapter(slot->adapter);
slot->adapter = NULL;
ida_simple_remove(&fmc_slot_ida, slot->dev.id);
slot->dev.id = -1;
}
static const struct device_type fmc_slot_type = {
......@@ -115,6 +116,7 @@ static void fmc_carrier_release(struct device *dev)
struct fmc_carrier *carrier = to_fmc_carrier(dev);
ida_simple_remove(&fmc_carrier_ida, carrier->dev.id);
carrier->dev.id = -1;
}
static const struct device_type fmc_carrier_type = {
......@@ -148,39 +150,42 @@ static struct fmc_slot *fmc_carrier_add_slot(struct fmc_carrier *carrier,
struct fmc_slot_info *info)
{
struct fmc_slot *slot;
int ret, err, id;
int ret, err;
if (WARN(!info, "Invalid slot info"))
return ERR_PTR(-EINVAL);
id = fmc_slot_id(carrier, info->lun);
id = ida_simple_get(&fmc_slot_ida, id, id + 1, GFP_KERNEL);
if (id < 0) {
dev_err(&carrier->dev,
"can't assign ID to slot (LUN: %dGA: 0x%02x)\n",
info->lun, info->ga);
err = id;
goto err_ida;
}
slot = devm_kzalloc(&carrier->dev, sizeof(struct fmc_slot), GFP_KERNEL);
if (!slot) {
err = -ENOMEM;
goto err_alloc;
}
slot->ga = info->ga;
slot->lun = info->lun;
slot->dev.class = &fmc_class;
slot->dev.type = &fmc_slot_type;
slot->dev.parent = &carrier->dev;
slot->dev.id = fmc_slot_id(carrier, info->lun);
slot->dev.id = ida_simple_get(&fmc_slot_ida,
slot->dev.id, slot->dev.id + 1,
GFP_KERNEL);
if (slot->dev.id < 0) {
dev_err(&carrier->dev,
"can't assign ID to slot (LUN: %dGA: 0x%02x)\n",
info->lun, info->ga);
err = slot->dev.id;
goto err_ida;
}
slot->adapter = i2c_get_adapter(info->i2c_bus_nr);
if (!slot->adapter) {
err = -ENODEV;
goto err_i2c;
}
slot->dev.class = &fmc_class;
slot->dev.type = &fmc_slot_type;
slot->dev.parent = &carrier->dev;
slot->dev.id = id;
err = dev_set_name(&slot->dev, "fmc-slot-%d.%d",
carrier->dev.id,
slot->lun);
......@@ -209,10 +214,10 @@ err_reg:
err_name:
i2c_put_adapter(slot->adapter);
err_i2c:
ida_simple_remove(&fmc_slot_ida, slot->dev.id);
err_ida:
devm_kfree(&carrier->dev, slot);
err_alloc:
ida_simple_remove(&fmc_slot_ida, id);
err_ida:
return ERR_PTR(err);
}
......@@ -248,7 +253,7 @@ int fmc_carrier_register(struct device *parent,
void *priv)
{
struct fmc_carrier *carrier;
int err, id, i;
int err, i;
ssize_t carrier_mem_size;
void *tmp_p;
......@@ -269,13 +274,6 @@ int fmc_carrier_register(struct device *parent,
return -EINVAL;
}
id = ida_simple_get(&fmc_carrier_ida, 0, 0, GFP_KERNEL);
if (id < 0) {
dev_err(parent, "FMC can't assign ID to carrier\n");
err = id;
goto err_ida;
}
carrier_mem_size = sizeof(struct fmc_carrier);
carrier_mem_size += sizeof(struct fmc_slot *) * nr_slot;
carrier = devm_kzalloc(parent, carrier_mem_size, GFP_KERNEL);
......@@ -292,7 +290,13 @@ int fmc_carrier_register(struct device *parent,
carrier->dev.class = &fmc_class;
carrier->dev.type = &fmc_carrier_type;
carrier->dev.parent = parent;
carrier->dev.id = id;
carrier->dev.id = ida_simple_get(&fmc_carrier_ida, 0, 0, GFP_KERNEL);
if (carrier->dev.id < 0) {
dev_err(parent, "FMC can't assign ID to carrier\n");
err = carrier->dev.id;
goto err_ida;
}
err = dev_set_name(&carrier->dev, "fmc-carrier-%x", carrier->dev.id);
if (err)
goto err_name;
......@@ -320,10 +324,10 @@ err_slot:
device_unregister(&carrier->dev);
err_reg:
err_name:
ida_simple_remove(&fmc_carrier_ida, carrier->dev.id);
err_ida:
devm_kfree(parent, carrier);
err_alloc:
ida_simple_remove(&fmc_carrier_ida, id);
err_ida:
dev_err(parent, "FMC carrier registration: failed %d\n", err);
return err;
}
......
......@@ -196,6 +196,7 @@ static int __fmc_slot_eeprom_add(struct fmc_slot *slot,
if (IS_ERR_OR_NULL(slot->nvmem)) {
int err = PTR_ERR(slot->nvmem);
slot->nvmem = NULL;
dev_err(&slot->dev, "Can't find attached EEPROM (%d)\n", err);
return err;
}
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment