Skip to content

Commit 8693ae8

Browse files
ikepanhcMatthew Garrett
authored andcommitted
ideapad: pass ideapad_priv as argument (part 1)
Passing ideapad_priv as argument and try not to using too much global variable. This is part 1 for platform driver and input device. Signed-off-by: Ike Panhc <ike.pan@canonical.com> Signed-off-by: Matthew Garrett <mjg@redhat.com>
1 parent a4b5a27 commit 8693ae8

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

drivers/platform/x86/ideapad-laptop.c

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -301,37 +301,37 @@ static struct attribute_group ideapad_attribute_group = {
301301
.attrs = ideapad_attributes
302302
};
303303

304-
static int __devinit ideapad_platform_init(void)
304+
static int __devinit ideapad_platform_init(struct ideapad_private *priv)
305305
{
306306
int result;
307307

308-
ideapad_priv->platform_device = platform_device_alloc("ideapad", -1);
309-
if (!ideapad_priv->platform_device)
308+
priv->platform_device = platform_device_alloc("ideapad", -1);
309+
if (!priv->platform_device)
310310
return -ENOMEM;
311-
platform_set_drvdata(ideapad_priv->platform_device, ideapad_priv);
311+
platform_set_drvdata(priv->platform_device, priv);
312312

313-
result = platform_device_add(ideapad_priv->platform_device);
313+
result = platform_device_add(priv->platform_device);
314314
if (result)
315315
goto fail_platform_device;
316316

317-
result = sysfs_create_group(&ideapad_priv->platform_device->dev.kobj,
317+
result = sysfs_create_group(&priv->platform_device->dev.kobj,
318318
&ideapad_attribute_group);
319319
if (result)
320320
goto fail_sysfs;
321321
return 0;
322322

323323
fail_sysfs:
324-
platform_device_del(ideapad_priv->platform_device);
324+
platform_device_del(priv->platform_device);
325325
fail_platform_device:
326-
platform_device_put(ideapad_priv->platform_device);
326+
platform_device_put(priv->platform_device);
327327
return result;
328328
}
329329

330-
static void ideapad_platform_exit(void)
330+
static void ideapad_platform_exit(struct ideapad_private *priv)
331331
{
332-
sysfs_remove_group(&ideapad_priv->platform_device->dev.kobj,
332+
sysfs_remove_group(&priv->platform_device->dev.kobj,
333333
&ideapad_attribute_group);
334-
platform_device_unregister(ideapad_priv->platform_device);
334+
platform_device_unregister(priv->platform_device);
335335
}
336336

337337
/*
@@ -343,7 +343,7 @@ static const struct key_entry ideapad_keymap[] = {
343343
{ KE_END, 0 },
344344
};
345345

346-
static int __devinit ideapad_input_init(void)
346+
static int __devinit ideapad_input_init(struct ideapad_private *priv)
347347
{
348348
struct input_dev *inputdev;
349349
int error;
@@ -357,7 +357,7 @@ static int __devinit ideapad_input_init(void)
357357
inputdev->name = "Ideapad extra buttons";
358358
inputdev->phys = "ideapad/input0";
359359
inputdev->id.bustype = BUS_HOST;
360-
inputdev->dev.parent = &ideapad_priv->platform_device->dev;
360+
inputdev->dev.parent = &priv->platform_device->dev;
361361

362362
error = sparse_keymap_setup(inputdev, ideapad_keymap, NULL);
363363
if (error) {
@@ -371,7 +371,7 @@ static int __devinit ideapad_input_init(void)
371371
goto err_free_keymap;
372372
}
373373

374-
ideapad_priv->inputdev = inputdev;
374+
priv->inputdev = inputdev;
375375
return 0;
376376

377377
err_free_keymap:
@@ -381,16 +381,17 @@ static int __devinit ideapad_input_init(void)
381381
return error;
382382
}
383383

384-
static void __devexit ideapad_input_exit(void)
384+
static void __devexit ideapad_input_exit(struct ideapad_private *priv)
385385
{
386-
sparse_keymap_free(ideapad_priv->inputdev);
387-
input_unregister_device(ideapad_priv->inputdev);
388-
ideapad_priv->inputdev = NULL;
386+
sparse_keymap_free(priv->inputdev);
387+
input_unregister_device(priv->inputdev);
388+
priv->inputdev = NULL;
389389
}
390390

391-
static void ideapad_input_report(unsigned long scancode)
391+
static void ideapad_input_report(struct ideapad_private *priv,
392+
unsigned long scancode)
392393
{
393-
sparse_keymap_report_event(ideapad_priv->inputdev, scancode, 1, true);
394+
sparse_keymap_report_event(priv->inputdev, scancode, 1, true);
394395
}
395396

396397
/*
@@ -417,11 +418,11 @@ static int __devinit ideapad_acpi_add(struct acpi_device *adevice)
417418
priv->handle = adevice->handle;
418419
dev_set_drvdata(&adevice->dev, priv);
419420

420-
ret = ideapad_platform_init();
421+
ret = ideapad_platform_init(priv);
421422
if (ret)
422423
goto platform_failed;
423424

424-
ret = ideapad_input_init();
425+
ret = ideapad_input_init(priv);
425426
if (ret)
426427
goto input_failed;
427428

@@ -434,7 +435,7 @@ static int __devinit ideapad_acpi_add(struct acpi_device *adevice)
434435
return 0;
435436

436437
input_failed:
437-
ideapad_platform_exit();
438+
ideapad_platform_exit(priv);
438439
platform_failed:
439440
kfree(priv);
440441
return ret;
@@ -447,8 +448,8 @@ static int __devexit ideapad_acpi_remove(struct acpi_device *adevice, int type)
447448

448449
for (i = IDEAPAD_DEV_WLAN; i < IDEAPAD_DEV_KILLSW; i++)
449450
ideapad_unregister_rfkill(adevice, i);
450-
ideapad_input_exit();
451-
ideapad_platform_exit();
451+
ideapad_input_exit(priv);
452+
ideapad_platform_exit(priv);
452453
dev_set_drvdata(&adevice->dev, NULL);
453454
kfree(priv);
454455

@@ -457,6 +458,7 @@ static int __devexit ideapad_acpi_remove(struct acpi_device *adevice, int type)
457458

458459
static void ideapad_acpi_notify(struct acpi_device *adevice, u32 event)
459460
{
461+
struct ideapad_private *priv = dev_get_drvdata(&adevice->dev);
460462
acpi_handle handle = adevice->handle;
461463
unsigned long vpc1, vpc2, vpc_bit;
462464

@@ -471,7 +473,7 @@ static void ideapad_acpi_notify(struct acpi_device *adevice, u32 event)
471473
if (vpc_bit == 9)
472474
ideapad_sync_rfk_state(adevice);
473475
else
474-
ideapad_input_report(vpc_bit);
476+
ideapad_input_report(priv, vpc_bit);
475477
}
476478
}
477479
}

0 commit comments

Comments
 (0)