Commit be23bf8e authored by Alessandro Rubini's avatar Alessandro Rubini

drivers: some error checking

Fix use of index (reval of ->validate) and allow the method to be
missing from the device. Similarly, allow for reprogram to be missing.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 29f077e4
......@@ -31,9 +31,10 @@ struct fmc_gpio t_gpio[] = {
int t_probe(struct fmc_device *fmc)
{
int ret;
int index;
int index = 0;
index = fmc->op->validate(fmc, &t_drv);
if (fmc->op->validate)
index = fmc->op->validate(fmc, &t_drv);
if (index < 0)
return -EINVAL; /* not our device: invalid */
......@@ -44,7 +45,9 @@ int t_probe(struct fmc_device *fmc)
fmc->op->gpio_config(fmc, t_gpio, ARRAY_SIZE(t_gpio));
/* Reprogram, if asked to. ESRCH == no filename specified */
ret = fmc->op->reprogram(fmc, &t_drv,"");
ret = -ESRCH;
if (fmc->op->reprogram)
ret = fmc->op->reprogram(fmc, &t_drv,"");
if (ret == -ESRCH)
ret = 0;
if (ret < 0)
......
......@@ -105,7 +105,7 @@ static int fwe_run(struct fmc_device *fmc, const struct firmware *fw, char *s)
*/
int fwe_probe(struct fmc_device *fmc)
{
int err, index;
int err, index = 0;
const struct firmware *fw;
struct device *dev = fmc->hwdev;
char *s;
......@@ -115,7 +115,13 @@ int fwe_probe(struct fmc_device *fmc)
KBUILD_MODNAME);
return -ENODEV;
}
index = fmc->op->validate(fmc, &fwe_drv);
if (fmc->op->validate)
index = fmc->op->validate(fmc, &fwe_drv);
if (index >= fwe_file_n) {
dev_err(dev, "%s: device returned index %i out of range\n",
KBUILD_MODNAME, index);
return -ENODEV;
}
s = fwe_file[index];
if (!s) {
dev_err(dev, "%s: no filename given: not programming\n",
......
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