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[] = { ...@@ -31,9 +31,10 @@ struct fmc_gpio t_gpio[] = {
int t_probe(struct fmc_device *fmc) int t_probe(struct fmc_device *fmc)
{ {
int ret; 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) if (index < 0)
return -EINVAL; /* not our device: invalid */ return -EINVAL; /* not our device: invalid */
...@@ -44,7 +45,9 @@ int t_probe(struct fmc_device *fmc) ...@@ -44,7 +45,9 @@ int t_probe(struct fmc_device *fmc)
fmc->op->gpio_config(fmc, t_gpio, ARRAY_SIZE(t_gpio)); fmc->op->gpio_config(fmc, t_gpio, ARRAY_SIZE(t_gpio));
/* Reprogram, if asked to. ESRCH == no filename specified */ /* 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) if (ret == -ESRCH)
ret = 0; ret = 0;
if (ret < 0) if (ret < 0)
......
...@@ -105,7 +105,7 @@ static int fwe_run(struct fmc_device *fmc, const struct firmware *fw, char *s) ...@@ -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 fwe_probe(struct fmc_device *fmc)
{ {
int err, index; int err, index = 0;
const struct firmware *fw; const struct firmware *fw;
struct device *dev = fmc->hwdev; struct device *dev = fmc->hwdev;
char *s; char *s;
...@@ -115,7 +115,13 @@ int fwe_probe(struct fmc_device *fmc) ...@@ -115,7 +115,13 @@ int fwe_probe(struct fmc_device *fmc)
KBUILD_MODNAME); KBUILD_MODNAME);
return -ENODEV; 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]; s = fwe_file[index];
if (!s) { if (!s) {
dev_err(dev, "%s: no filename given: not programming\n", 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