linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Qiao Zhou <zhouqiao@marvell.com>
Cc: sameo@linux.intel.com, linux-input@vger.kernel.org
Subject: Re: [PATCH V8] input: add onkey support to 88PM80X PMIC
Date: Fri, 13 Jul 2012 00:34:47 -0700	[thread overview]
Message-ID: <20120713073447.GC2223@core.coreip.homeip.net> (raw)
In-Reply-To: <1341997504-23522-2-git-send-email-zhouqiao@marvell.com>

Hi Qiao,

On Wed, Jul 11, 2012 at 05:05:04PM +0800, Qiao Zhou wrote:
> +
> +static int __devinit pm80x_onkey_probe(struct platform_device *pdev)
> +{
> +
> +	struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent);
> +	struct pm80x_onkey_info *info;
> +	int err;
> +
> +	info =
> +	    devm_kzalloc(&pdev->dev, sizeof(struct pm80x_onkey_info),
> +			 GFP_KERNEL);

Please switch to normal kzalloc/kfree, because:

1. You are not using devm_* API correctly - it was designed so that you
do not need to explicitly call devm_free as resources will be freed when
device is unbound from the driver (or if binf fails). But since you are
explicitly calling devm_free() in error paths and in
pm80x_onkey_remove() there is no point in even using this API.

2. At this time I prefer not use devm_ API in input drivers are it
causes mixed resource tracking strategy (automatic vs manual) which is
confusing.

> +	if (!info)
> +		return -ENOMEM;
> +
> +	info->pm80x = chip;
> +
> +	info->irq = platform_get_irq(pdev, 0);
> +	if (info->irq < 0) {
> +		dev_err(&pdev->dev, "No IRQ resource!\n");
> +		err = -EINVAL;
> +		goto out;
> +	}
> +
> +	info->map = info->pm80x->regmap;
> +	if (!info->map) {
> +		dev_err(&pdev->dev, "no regmap!\n");
> +		err = -EINVAL;
> +		goto out;
> +	}
> +
> +	err = pm80x_request_irq(info->pm80x, info->irq, pm80x_onkey_handler,
> +					    IRQF_ONESHOT, "onkey", info);
> +	if (err < 0) {
> +		dev_err(&pdev->dev, "Failed to request IRQ: #%d: %d\n",
> +			info->irq, err);
> +		goto out;
> +	}
> 

If we get IRQ here we'll OOPS. Please allocate input device before
requesting IRQ (but register like you do now, as the last action, after
requesting IRQ).

+
> +	info->idev = input_allocate_device();
> +	if (!info->idev) {
> +		dev_err(&pdev->dev, "Failed to allocate input dev\n");
> +		err = -ENOMEM;
> +		goto out_irq;
> +	}
> +
> +	info->idev->name = "88pm80x_on";
> +	info->idev->phys = "88pm80x_on/input0";
> +	info->idev->id.bustype = BUS_I2C;
> +	info->idev->dev.parent = &pdev->dev;
> +	info->idev->evbit[0] = BIT_MASK(EV_KEY);
> +	info->idev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);

	__set_bit(KEY_POWER, info->idev->keybit);

> +
> +	err = input_register_device(info->idev);
> +	if (err) {
> +		dev_err(&pdev->dev, "Can't register input device: %d\n", err);
> +		goto out_reg;
> +	}
> +
> +	platform_set_drvdata(pdev, info);
> +
> +	/* Enable long onkey detection */
> +	regmap_update_bits(info->map, PM800_RTC_MISC4, PM800_LONG_ONKEY_EN,
> +			   PM800_LONG_ONKEY_EN);
> +	/* Set 8-second interval */
> +	regmap_update_bits(info->map, PM800_RTC_MISC3,
> +			   PM800_LONKEY_PRESS_TIME_MASK,
> +			   PM800_LONKEY_PRESS_TIME);
> +
> +	device_init_wakeup(&pdev->dev, 1);
> +	return 0;
> +
> +out_reg:
> +	input_free_device(info->idev);
> +out_irq:
> +	pm80x_free_irq(info->pm80x, info->irq, info);
> +out:
> +	devm_kfree(&pdev->dev, info);

	kfree(info);

> +	return err;
> +}
> +
> +static int __devexit pm80x_onkey_remove(struct platform_device *pdev)
> +{
> +	struct pm80x_onkey_info *info = platform_get_drvdata(pdev);
> +
> +	input_unregister_device(info->idev);

If interrupt comes here we'll OOPS. You need to free IRQ first.

> +	pm80x_free_irq(info->pm80x, info->irq, info);
> +	devm_kfree(&pdev->dev, info);
	kfree(info);
> +	return 0;
> +}
> +
> +static struct platform_driver pm80x_onkey_driver = {
> +	.driver = {
> +		   .name = "88pm80x-onkey",
> +		   .owner = THIS_MODULE,
> +		   .pm = &pm80x_onkey_pm_ops,
> +		   },
> +	.probe = pm80x_onkey_probe,
> +	.remove = __devexit_p(pm80x_onkey_remove),
> +};
> +
> +module_platform_driver(pm80x_onkey_driver);
> +
> +MODULE_LICENSE("GPL");
> +MODULE_DESCRIPTION("Marvell 88PM80x ONKEY driver");
> +MODULE_AUTHOR("Qiao Zhou <zhouqiao@marvell.com>");
> +MODULE_ALIAS("platform:88pm80x-onkey");
> diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
> index 7faf4a7..7c0f1ec 100644
> --- a/drivers/input/misc/Kconfig
> +++ b/drivers/input/misc/Kconfig
> @@ -22,6 +22,16 @@ config INPUT_88PM860X_ONKEY
>  	  To compile this driver as a module, choose M here: the module
>  	  will be called 88pm860x_onkey.
>  
> +config INPUT_88PM80X_ONKEY
> +	tristate "88PM80x ONKEY support"
> +	depends on MFD_88PM800
> +	help
> +	  Support the ONKEY of Marvell 88PM80x PMICs as an input device
> +	  reporting power button status.
> +
> +	  To compile this driver as a module, choose M here: the module
> +	  will be called 88pm80x_onkey.
> +
>  config INPUT_AB8500_PONKEY
>  	tristate "AB8500 Pon (PowerOn) Key"
>  	depends on AB8500_CORE
> diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
> index f55cdf4..83fe6f5 100644
> --- a/drivers/input/misc/Makefile
> +++ b/drivers/input/misc/Makefile
> @@ -5,6 +5,7 @@
>  # Each configuration option enables a list of files.
>  
>  obj-$(CONFIG_INPUT_88PM860X_ONKEY)	+= 88pm860x_onkey.o
> +obj-$(CONFIG_INPUT_88PM80X_ONKEY)	+= 88pm80x_onkey.o
>  obj-$(CONFIG_INPUT_AB8500_PONKEY)	+= ab8500-ponkey.o
>  obj-$(CONFIG_INPUT_AD714X)		+= ad714x.o
>  obj-$(CONFIG_INPUT_AD714X_I2C)		+= ad714x-i2c.o
> -- 
> 1.7.0.4
> 

Thanks!

-- 
Dmitry

  reply	other threads:[~2012-07-13  7:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-11  9:05 [PATCH V8] add 88pm80x onkey driver Qiao Zhou
2012-07-11  9:05 ` [PATCH V8] input: add onkey support to 88PM80X PMIC Qiao Zhou
2012-07-13  7:34   ` Dmitry Torokhov [this message]
2012-07-13  7:39     ` Qiao Zhou
2012-07-13  0:52 ` [PATCH V8] add 88pm80x onkey driver Qiao Zhou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120713073447.GC2223@core.coreip.homeip.net \
    --to=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=sameo@linux.intel.com \
    --cc=zhouqiao@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).