Commit 2429d863868edb611f033c9ce4db519fbc270240
Committed by
Samuel Ortiz
1 parent
136d982eca
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
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>
Showing 1 changed file with 18 additions and 16 deletions Side-by-side Diff
drivers/mfd/max77693.c
... | ... | @@ -114,35 +114,37 @@ |
114 | 114 | u8 reg_data; |
115 | 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 | 122 | max77693 = devm_kzalloc(&i2c->dev, |
118 | 123 | sizeof(struct max77693_dev), GFP_KERNEL); |
119 | 124 | if (max77693 == NULL) |
120 | 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 | 127 | i2c_set_clientdata(i2c, max77693); |
131 | 128 | max77693->dev = &i2c->dev; |
132 | 129 | max77693->i2c = i2c; |
133 | 130 | max77693->irq = i2c->irq; |
134 | 131 | max77693->type = id->driver_data; |
135 | 132 | |
136 | - if (!pdata) | |
137 | - goto err_regmap; | |
133 | + max77693->regmap = devm_regmap_init_i2c(i2c, &max77693_regmap_config); | |
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 | 141 | max77693->wakeup = pdata->wakeup; |
140 | 142 | |
141 | - if (max77693_read_reg(max77693->regmap, | |
142 | - MAX77693_PMIC_REG_PMIC_ID2, ®_data) < 0) { | |
143 | + ret = max77693_read_reg(max77693->regmap, MAX77693_PMIC_REG_PMIC_ID2, | |
144 | + ®_data); | |
145 | + if (ret < 0) { | |
143 | 146 | dev_err(max77693->dev, "device not found on this channel\n"); |
144 | - ret = -ENODEV; | |
145 | - goto err_regmap; | |
147 | + return ret; | |
146 | 148 | } else |
147 | 149 | dev_info(max77693->dev, "device ID: 0x%x\n", reg_data); |
148 | 150 | |
... | ... | @@ -163,7 +165,7 @@ |
163 | 165 | ret = PTR_ERR(max77693->regmap_muic); |
164 | 166 | dev_err(max77693->dev, |
165 | 167 | "failed to allocate register map: %d\n", ret); |
166 | - goto err_regmap; | |
168 | + goto err_regmap_muic; | |
167 | 169 | } |
168 | 170 | |
169 | 171 | ret = max77693_irq_init(max77693); |
170 | 172 | |
... | ... | @@ -184,9 +186,9 @@ |
184 | 186 | err_mfd: |
185 | 187 | max77693_irq_exit(max77693); |
186 | 188 | err_irq: |
189 | +err_regmap_muic: | |
187 | 190 | i2c_unregister_device(max77693->muic); |
188 | 191 | i2c_unregister_device(max77693->haptic); |
189 | -err_regmap: | |
190 | 192 | return ret; |
191 | 193 | } |
192 | 194 |