From patchwork Thu Feb 5 08:29:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sonic zhang X-Patchwork-Id: 5782841 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C56D2BF440 for ; Thu, 5 Feb 2015 08:31:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C8F78201BB for ; Thu, 5 Feb 2015 08:31:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A5094201CE for ; Thu, 5 Feb 2015 08:31:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754805AbbBEIbd (ORCPT ); Thu, 5 Feb 2015 03:31:33 -0500 Received: from mail-bl2on0092.outbound.protection.outlook.com ([65.55.169.92]:20032 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754745AbbBEIbd (ORCPT ); Thu, 5 Feb 2015 03:31:33 -0500 X-Greylist: delayed 3495 seconds by postgrey-1.27 at vger.kernel.org; Thu, 05 Feb 2015 03:31:32 EST Received: from CH1PR03CA012.namprd03.prod.outlook.com (10.255.156.157) by DM2PR0301MB0752.namprd03.prod.outlook.com (25.160.97.148) with Microsoft SMTP Server (TLS) id 15.1.75.20; Thu, 5 Feb 2015 08:31:24 +0000 Received: from BN1BFFO11FD043.protection.gbl (10.255.156.132) by CH1PR03CA012.outlook.office365.com (10.255.156.157) with Microsoft SMTP Server (TLS) id 15.1.75.20 via Frontend Transport; Thu, 5 Feb 2015 08:31:23 +0000 Received: from nwd2mta2.analog.com (137.71.25.57) by BN1BFFO11FD043.mail.protection.outlook.com (10.58.144.106) with Microsoft SMTP Server (TLS) id 15.1.87.10 via Frontend Transport; Thu, 5 Feb 2015 08:31:23 +0000 Received: from NWD2HUBCAS8.ad.analog.com (nwd2hubcas8.ad.analog.com [10.64.72.141]) by nwd2mta2.analog.com (8.13.8/8.13.8) with ESMTP id t15BdQeh011233 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Thu, 5 Feb 2015 06:39:27 -0500 Received: from zeus.spd.analog.com (10.64.82.11) by NWD2HUBCAS8.ad.analog.com (10.64.72.141) with Microsoft SMTP Server id 14.3.210.2; Thu, 5 Feb 2015 03:30:46 -0500 Received: from linux.site ([10.99.22.20]) by zeus.spd.analog.com (8.14.6/8.14.6) with ESMTP id t158Ujfx003712; Thu, 5 Feb 2015 03:30:45 -0500 Received: from nine.ad.analog.com (unknown [10.99.24.95]) by linux.site (Postfix) with ESMTP id 5113C3B00E88; Wed, 4 Feb 2015 17:34:22 -0700 (MST) From: Sonic Zhang To: Dmitry Torokhov , CC: Michael Hennerich , , Sonic Zhang Subject: [PATCH v2] bfin_rotary: convert to use managed resources Date: Thu, 5 Feb 2015 16:29:13 +0800 Message-ID: <1423124953-9564-1-git-send-email-sonic.adi@gmail.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Matching-Connectors: 130675986833988745; (52f37747-95c3-483a-bd05-08d153b03fac); () Received-SPF: SoftFail (protection.outlook.com: domain of transitioning gmail.com discourages use of 137.71.25.57 as permitted sender) Authentication-Results: spf=softfail (sender IP is 137.71.25.57) smtp.mailfrom=sonic.adi@gmail.com; vger.kernel.org; dkim=none (message not signed) header.d=none; X-Forefront-Antispam-Report: CIP:137.71.25.57; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(77096005)(61266001)(50226001)(55446002)(82202001)(105596002)(229853001)(92566002)(50466002)(47776003)(83322999)(87936001)(36756003)(33646002)(6806004)(48376002)(86362001)(19580405001)(19580395003)(46102003)(73392002)(50986999)(87572001)(62966003)(77156002)(81442002)(76482003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR0301MB0752; H:nwd2mta2.analog.com; FPR:; SPF:SoftFail; MLV:sfv; LANG:en; X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB0752; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004); SRVR:DM2PR0301MB0752; X-Forefront-PRVS: 0478C23FE0 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(401004)(400005); SRVR:DM2PR0301MB0752; X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Feb 2015 08:31:23.1648 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[137.71.25.57] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB0752 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sonic Zhang - remap rotary register physical address into kernel space in probe - replace kzalloc with devm_kzalloc - replace request_irq with devm_request_irq - remove memory free and irq free from the device remove function - use devm_input_allocate_device v2-changes: - remove rotary register address remap operation from this patch - Use devm_add_action() to integrate freeing of pins into the rest of devm* unwind sequence. Signed-off-by: Sonic Zhang --- drivers/input/misc/bfin_rotary.c | 84 ++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 45 deletions(-) diff --git a/drivers/input/misc/bfin_rotary.c b/drivers/input/misc/bfin_rotary.c index dd929ad..80f66e7 100644 --- a/drivers/input/misc/bfin_rotary.c +++ b/drivers/input/misc/bfin_rotary.c @@ -93,6 +93,13 @@ static irqreturn_t bfin_rotary_isr(int irq, void *dev_id) return IRQ_HANDLED; } + +static void bfin_rotary_free_action(void *data) +{ + unsigned short *pin_list = (unsigned short *)data; + peripheral_free_list(pin_list); +} + static int bfin_rotary_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -102,6 +109,31 @@ static int bfin_rotary_probe(struct platform_device *pdev) struct input_dev *input; int error; + rotary = devm_kzalloc(dev, sizeof(struct bfin_rot), GFP_KERNEL); + if (!rotary) { + dev_err(dev, "fail to malloc bfin_rot\n"); + return -ENOMEM; + } + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + rotary->base = devm_ioremap_resource(dev, res); + if (IS_ERR(rotary->base)) + return PTR_ERR(rotary->base); + + rotary->irq = platform_get_irq(pdev, 0); + if (rotary->irq < 0) { + dev_err(dev, "No rotary IRQ specified\n"); + return -ENOENT; + } + + error = devm_request_irq(dev, rotary->irq, bfin_rotary_isr, + 0, dev_name(&pdev->dev), pdev); + if (error) { + dev_err(dev, "unable to claim irq %d; error %d\n", + rotary->irq, error); + return error; + } + /* Basic validation */ if ((pdata->rotary_up_key && !pdata->rotary_down_key) || (!pdata->rotary_up_key && pdata->rotary_down_key)) { @@ -110,23 +142,15 @@ static int bfin_rotary_probe(struct platform_device *pdev) error = peripheral_request_list(pdata->pin_list, dev_name(&pdev->dev)); if (error) { - dev_err(&pdev->dev, "requesting peripherals failed\n"); + dev_err(dev, "requesting peripherals failed\n"); return error; } - rotary = kzalloc(sizeof(struct bfin_rot), GFP_KERNEL); - input = input_allocate_device(); - if (!rotary || !input) { - error = -ENOMEM; - goto out1; - } + devm_add_action(dev, bfin_rotary_free_action, pdata->pin_list); - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - rotary->base = devm_ioremap_resource(dev, res); - if (IS_ERR(rotary->base)) { - error = PTR_ERR(rotary->base); - goto out1; - } + input = devm_input_allocate_device(dev); + if (!input) + return -ENOMEM; rotary->input = input; @@ -135,10 +159,6 @@ static int bfin_rotary_probe(struct platform_device *pdev) rotary->button_key = pdata->rotary_button_key; rotary->rel_code = pdata->rotary_rel_code; - error = rotary->irq = platform_get_irq(pdev, 0); - if (error < 0) - goto out1; - input->name = pdev->name; input->phys = "bfin-rotary/input0"; input->dev.parent = &pdev->dev; @@ -164,20 +184,10 @@ static int bfin_rotary_probe(struct platform_device *pdev) __set_bit(rotary->button_key, input->keybit); } - error = request_irq(rotary->irq, bfin_rotary_isr, - 0, dev_name(&pdev->dev), pdev); - if (error) { - dev_err(&pdev->dev, - "unable to claim irq %d; error %d\n", - rotary->irq, error); - goto out1; - } - error = input_register_device(input); if (error) { - dev_err(&pdev->dev, - "unable to register input device (%d)\n", error); - goto out2; + dev_err(dev, "unable to register input device (%d)\n", error); + return error; } if (pdata->rotary_button_key) @@ -201,31 +211,15 @@ static int bfin_rotary_probe(struct platform_device *pdev) device_init_wakeup(&pdev->dev, 1); return 0; - -out2: - free_irq(rotary->irq, pdev); -out1: - input_free_device(input); - kfree(rotary); - peripheral_free_list(pdata->pin_list); - - return error; } static int bfin_rotary_remove(struct platform_device *pdev) { - struct bfin_rotary_platform_data *pdata = dev_get_platdata(&pdev->dev); struct bfin_rot *rotary = platform_get_drvdata(pdev); writew(0, rotary->base + CNT_CONFIG_OFF); writew(0, rotary->base + CNT_IMASK_OFF); - free_irq(rotary->irq, pdev); - input_unregister_device(rotary->input); - peripheral_free_list(pdata->pin_list); - - kfree(rotary); - return 0; }