diff options
author | Axel Lin <axel.lin@ingics.com> | 2012-12-24 11:28:36 -0500 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2013-01-21 21:02:22 -0500 |
commit | 2429d863868edb611f033c9ce4db519fbc270240 (patch) | |
tree | 943dc4db17e091a2fcba3f291307d9214610837d /drivers/mfd/max77693.c | |
parent | 136d982ecae912c815587a1653f235f0ef570da8 (diff) |
mfd: max77693: Init max77693->dev before using it
Current code uses max77693->dev in the dev_err call before setting it to
&i2c->dev. Fix it.
This patch also includes below cleanups:
- Move checking pdata earlier and show dev_err if no platform data found.
- Remove unnecessary err_regmap goto label.
- Unregister i2c devices if regmap init for muic fails.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/mfd/max77693.c')
-rw-r--r-- | drivers/mfd/max77693.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/drivers/mfd/max77693.c b/drivers/mfd/max77693.c index cc5155e20494..9e60fed5ff82 100644 --- a/drivers/mfd/max77693.c +++ b/drivers/mfd/max77693.c | |||
@@ -114,35 +114,37 @@ static int max77693_i2c_probe(struct i2c_client *i2c, | |||
114 | u8 reg_data; | 114 | u8 reg_data; |
115 | int ret = 0; | 115 | int ret = 0; |
116 | 116 | ||
117 | if (!pdata) { | ||
118 | dev_err(&i2c->dev, "No platform data found.\n"); | ||
119 | return -EINVAL; | ||
120 | } | ||
121 | |||
117 | max77693 = devm_kzalloc(&i2c->dev, | 122 | max77693 = devm_kzalloc(&i2c->dev, |
118 | sizeof(struct max77693_dev), GFP_KERNEL); | 123 | sizeof(struct max77693_dev), GFP_KERNEL); |
119 | if (max77693 == NULL) | 124 | if (max77693 == NULL) |
120 | return -ENOMEM; | 125 | return -ENOMEM; |
121 | 126 | ||
122 | max77693->regmap = devm_regmap_init_i2c(i2c, &max77693_regmap_config); | ||
123 | if (IS_ERR(max77693->regmap)) { | ||
124 | ret = PTR_ERR(max77693->regmap); | ||
125 | dev_err(max77693->dev,"failed to allocate register map: %d\n", | ||
126 | ret); | ||
127 | goto err_regmap; | ||
128 | } | ||
129 | |||
130 | i2c_set_clientdata(i2c, max77693); | 127 | i2c_set_clientdata(i2c, max77693); |
131 | max77693->dev = &i2c->dev; | 128 | max77693->dev = &i2c->dev; |
132 | max77693->i2c = i2c; | 129 | max77693->i2c = i2c; |
133 | max77693->irq = i2c->irq; | 130 | max77693->irq = i2c->irq; |
134 | max77693->type = id->driver_data; | 131 | max77693->type = id->driver_data; |
135 | 132 | ||
136 | if (!pdata) | 133 | max77693->regmap = devm_regmap_init_i2c(i2c, &max77693_regmap_config); |
137 | goto err_regmap; | 134 | if (IS_ERR(max77693->regmap)) { |
135 | ret = PTR_ERR(max77693->regmap); | ||
136 | dev_err(max77693->dev, "failed to allocate register map: %d\n", | ||
137 | ret); | ||
138 | return ret; | ||
139 | } | ||
138 | 140 | ||
139 | max77693->wakeup = pdata->wakeup; | 141 | max77693->wakeup = pdata->wakeup; |
140 | 142 | ||
141 | if (max77693_read_reg(max77693->regmap, | 143 | ret = max77693_read_reg(max77693->regmap, MAX77693_PMIC_REG_PMIC_ID2, |
142 | MAX77693_PMIC_REG_PMIC_ID2, ®_data) < 0) { | 144 | ®_data); |
145 | if (ret < 0) { | ||
143 | dev_err(max77693->dev, "device not found on this channel\n"); | 146 | dev_err(max77693->dev, "device not found on this channel\n"); |
144 | ret = -ENODEV; | 147 | return ret; |
145 | goto err_regmap; | ||
146 | } else | 148 | } else |
147 | dev_info(max77693->dev, "device ID: 0x%x\n", reg_data); | 149 | dev_info(max77693->dev, "device ID: 0x%x\n", reg_data); |
148 | 150 | ||
@@ -163,7 +165,7 @@ static int max77693_i2c_probe(struct i2c_client *i2c, | |||
163 | ret = PTR_ERR(max77693->regmap_muic); | 165 | ret = PTR_ERR(max77693->regmap_muic); |
164 | dev_err(max77693->dev, | 166 | dev_err(max77693->dev, |
165 | "failed to allocate register map: %d\n", ret); | 167 | "failed to allocate register map: %d\n", ret); |
166 | goto err_regmap; | 168 | goto err_regmap_muic; |
167 | } | 169 | } |
168 | 170 | ||
169 | ret = max77693_irq_init(max77693); | 171 | ret = max77693_irq_init(max77693); |
@@ -184,9 +186,9 @@ static int max77693_i2c_probe(struct i2c_client *i2c, | |||
184 | err_mfd: | 186 | err_mfd: |
185 | max77693_irq_exit(max77693); | 187 | max77693_irq_exit(max77693); |
186 | err_irq: | 188 | err_irq: |
189 | err_regmap_muic: | ||
187 | i2c_unregister_device(max77693->muic); | 190 | i2c_unregister_device(max77693->muic); |
188 | i2c_unregister_device(max77693->haptic); | 191 | i2c_unregister_device(max77693->haptic); |
189 | err_regmap: | ||
190 | return ret; | 192 | return ret; |
191 | } | 193 | } |
192 | 194 | ||