1515#include <linux/slab.h>
1616
1717#include "charlcd.h"
18+ #include "hd44780_common.h"
1819
1920enum hd44780_pin {
2021 /* Order does matter due to writing to GPIO array subsets! */
@@ -179,8 +180,9 @@ static int hd44780_probe(struct platform_device *pdev)
179180 struct device * dev = & pdev -> dev ;
180181 unsigned int i , base ;
181182 struct charlcd * lcd ;
183+ struct hd44780_common * hdc ;
182184 struct hd44780 * hd ;
183- int ifwidth , ret ;
185+ int ifwidth , ret = - ENOMEM ;
184186
185187 /* Required pins */
186188 ifwidth = gpiod_count (dev , "data" );
@@ -198,56 +200,64 @@ static int hd44780_probe(struct platform_device *pdev)
198200 return - EINVAL ;
199201 }
200202
203+ hdc = hd44780_common_alloc ();
204+ if (!hdc )
205+ return - ENOMEM ;
206+
201207 lcd = charlcd_alloc (sizeof (struct hd44780 ));
202208 if (!lcd )
203- return - ENOMEM ;
209+ goto fail1 ;
204210
205- hd = lcd -> drvdata ;
211+ hd = kzalloc (sizeof (struct hd44780 ), GFP_KERNEL );
212+ if (!hd )
213+ goto fail2 ;
206214
215+ hdc -> hd44780 = hd ;
216+ lcd -> drvdata = hdc ;
207217 for (i = 0 ; i < ifwidth ; i ++ ) {
208218 hd -> pins [base + i ] = devm_gpiod_get_index (dev , "data" , i ,
209219 GPIOD_OUT_LOW );
210220 if (IS_ERR (hd -> pins [base + i ])) {
211221 ret = PTR_ERR (hd -> pins [base + i ]);
212- goto fail ;
222+ goto fail3 ;
213223 }
214224 }
215225
216226 hd -> pins [PIN_CTRL_E ] = devm_gpiod_get (dev , "enable" , GPIOD_OUT_LOW );
217227 if (IS_ERR (hd -> pins [PIN_CTRL_E ])) {
218228 ret = PTR_ERR (hd -> pins [PIN_CTRL_E ]);
219- goto fail ;
229+ goto fail3 ;
220230 }
221231
222232 hd -> pins [PIN_CTRL_RS ] = devm_gpiod_get (dev , "rs" , GPIOD_OUT_HIGH );
223233 if (IS_ERR (hd -> pins [PIN_CTRL_RS ])) {
224234 ret = PTR_ERR (hd -> pins [PIN_CTRL_RS ]);
225- goto fail ;
235+ goto fail3 ;
226236 }
227237
228238 /* Optional pins */
229239 hd -> pins [PIN_CTRL_RW ] = devm_gpiod_get_optional (dev , "rw" ,
230240 GPIOD_OUT_LOW );
231241 if (IS_ERR (hd -> pins [PIN_CTRL_RW ])) {
232242 ret = PTR_ERR (hd -> pins [PIN_CTRL_RW ]);
233- goto fail ;
243+ goto fail3 ;
234244 }
235245
236246 hd -> pins [PIN_CTRL_BL ] = devm_gpiod_get_optional (dev , "backlight" ,
237247 GPIOD_OUT_LOW );
238248 if (IS_ERR (hd -> pins [PIN_CTRL_BL ])) {
239249 ret = PTR_ERR (hd -> pins [PIN_CTRL_BL ]);
240- goto fail ;
250+ goto fail3 ;
241251 }
242252
243253 /* Required properties */
244254 ret = device_property_read_u32 (dev , "display-height-chars" ,
245255 & lcd -> height );
246256 if (ret )
247- goto fail ;
257+ goto fail3 ;
248258 ret = device_property_read_u32 (dev , "display-width-chars" , & lcd -> width );
249259 if (ret )
250- goto fail ;
260+ goto fail3 ;
251261
252262 /*
253263 * On displays with more than two rows, the internal buffer width is
@@ -264,23 +274,28 @@ static int hd44780_probe(struct platform_device *pdev)
264274
265275 ret = charlcd_register (lcd );
266276 if (ret )
267- goto fail ;
277+ goto fail3 ;
268278
269279 platform_set_drvdata (pdev , lcd );
270280 return 0 ;
271281
272- fail :
273- charlcd_free (lcd );
282+ fail3 :
283+ kfree (hd );
284+ fail2 :
285+ kfree (lcd );
286+ fail1 :
287+ kfree (hdc );
274288 return ret ;
275289}
276290
277291static int hd44780_remove (struct platform_device * pdev )
278292{
279293 struct charlcd * lcd = platform_get_drvdata (pdev );
280294
295+ kfree (lcd -> drvdata );
281296 charlcd_unregister (lcd );
282297
283- charlcd_free (lcd );
298+ kfree (lcd );
284299 return 0 ;
285300}
286301
0 commit comments