diff options
| author | Julia Lawall <julia@diku.dk> | 2009-08-07 03:00:34 -0400 |
|---|---|---|
| committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2009-08-19 20:27:17 -0400 |
| commit | 6c75933c00049bee59562a18843a4f133ec2bfe4 (patch) | |
| tree | 57618062dd88af2c186610a5f880df48257f8d24 /arch/powerpc/sysdev | |
| parent | 8dcd038a13b8e322c49fe0d3e31a0deaba4fd5fd (diff) | |
powerpc/fsl_rio: Add kmalloc NULL tests
Check that the result of kmalloc/kzalloc is not NULL before dereferencing it.
The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@@
expression *x;
identifier f;
constant char *C;
@@
x = \(kmalloc\|kcalloc\|kzalloc\)(...);
... when != x == NULL
when != x != NULL
when != (x || ...)
(
kfree(x)
|
f(...,C,...,x,...)
|
*f(...,x,...)
|
*x->f
)
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'arch/powerpc/sysdev')
| -rw-r--r-- | arch/powerpc/sysdev/fsl_rio.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/arch/powerpc/sysdev/fsl_rio.c b/arch/powerpc/sysdev/fsl_rio.c index cbb3bed75d3c..757a83fe5e59 100644 --- a/arch/powerpc/sysdev/fsl_rio.c +++ b/arch/powerpc/sysdev/fsl_rio.c | |||
| @@ -1057,6 +1057,10 @@ int fsl_rio_setup(struct of_device *dev) | |||
| 1057 | law_start, law_size); | 1057 | law_start, law_size); |
| 1058 | 1058 | ||
| 1059 | ops = kmalloc(sizeof(struct rio_ops), GFP_KERNEL); | 1059 | ops = kmalloc(sizeof(struct rio_ops), GFP_KERNEL); |
| 1060 | if (!ops) { | ||
| 1061 | rc = -ENOMEM; | ||
| 1062 | goto err_ops; | ||
| 1063 | } | ||
| 1060 | ops->lcread = fsl_local_config_read; | 1064 | ops->lcread = fsl_local_config_read; |
| 1061 | ops->lcwrite = fsl_local_config_write; | 1065 | ops->lcwrite = fsl_local_config_write; |
| 1062 | ops->cread = fsl_rio_config_read; | 1066 | ops->cread = fsl_rio_config_read; |
| @@ -1064,6 +1068,10 @@ int fsl_rio_setup(struct of_device *dev) | |||
| 1064 | ops->dsend = fsl_rio_doorbell_send; | 1068 | ops->dsend = fsl_rio_doorbell_send; |
| 1065 | 1069 | ||
| 1066 | port = kzalloc(sizeof(struct rio_mport), GFP_KERNEL); | 1070 | port = kzalloc(sizeof(struct rio_mport), GFP_KERNEL); |
| 1071 | if (!port) { | ||
| 1072 | rc = -ENOMEM; | ||
| 1073 | goto err_port; | ||
| 1074 | } | ||
| 1067 | port->id = 0; | 1075 | port->id = 0; |
| 1068 | port->index = 0; | 1076 | port->index = 0; |
| 1069 | 1077 | ||
| @@ -1071,7 +1079,7 @@ int fsl_rio_setup(struct of_device *dev) | |||
| 1071 | if (!priv) { | 1079 | if (!priv) { |
| 1072 | printk(KERN_ERR "Can't alloc memory for 'priv'\n"); | 1080 | printk(KERN_ERR "Can't alloc memory for 'priv'\n"); |
| 1073 | rc = -ENOMEM; | 1081 | rc = -ENOMEM; |
| 1074 | goto err; | 1082 | goto err_priv; |
| 1075 | } | 1083 | } |
| 1076 | 1084 | ||
| 1077 | INIT_LIST_HEAD(&port->dbells); | 1085 | INIT_LIST_HEAD(&port->dbells); |
| @@ -1169,11 +1177,13 @@ int fsl_rio_setup(struct of_device *dev) | |||
| 1169 | 1177 | ||
| 1170 | return 0; | 1178 | return 0; |
| 1171 | err: | 1179 | err: |
| 1172 | if (priv) | 1180 | iounmap(priv->regs_win); |
| 1173 | iounmap(priv->regs_win); | ||
| 1174 | kfree(ops); | ||
| 1175 | kfree(priv); | 1181 | kfree(priv); |
| 1182 | err_priv: | ||
| 1176 | kfree(port); | 1183 | kfree(port); |
| 1184 | err_port: | ||
| 1185 | kfree(ops); | ||
| 1186 | err_ops: | ||
| 1177 | return rc; | 1187 | return rc; |
| 1178 | } | 1188 | } |
| 1179 | 1189 | ||
