Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1291197ybg; Fri, 18 Oct 2019 15:19:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqzDdVC7OpsCpDoTkUEWOOxT/f/vF2rJ3IEDErdaBPBnaGfD7c9VIptYzTk28lWq4owexi7j X-Received: by 2002:a17:906:ca50:: with SMTP id jx16mr10960387ejb.33.1571437143200; Fri, 18 Oct 2019 15:19:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571437143; cv=none; d=google.com; s=arc-20160816; b=BONiuLIFEzfnB53naHyCBbstO7oS27tfOZRd0g+CfMUkO/YqOjQ+8AWbi5A6iSL3j1 T5ZFCB7+jsE82+BCYwFLsdXLLjRKpiB+ycHd2t+eQc6O7bydMttSWWG4GmxdJ6bnalJD lpZo1I8iPIG9a/J8onIjlpm8yAVDaA9IGNDwgAeWDL9GMnAttfkOotu0G28MMzTEwHaU 2nHM8XwzheKfYmhpUBAfU/73J6A9TCSnPooBKsoI4rF/SlMCuiO3P7zVGeduo37Alxy3 X8ux3eDJ/Qh8vnFWDjWml7w9RiS4VrbRkzGcb4BgKI5xlx+HdZY0UuDMaDpyh7kc9DrP FKtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ee91/xG94vrK174Ap37BZY7hPtCqG3wuDv6y0inOwfc=; b=w5ixXjdalZXlDi0L+bFjO1Ap8bK26FwH4pDbluYASgiJqo3ZcLTUnzCmBJ8qvDR1Em 0g+6nV+o0p5fEcC7s0Fa5NNHp+OYk8+nLgkq+aGDQAWPTTLlYtdMFxHL8ewzdFRVfYns J4A9bfQleppnlczyupF3U1OAao51uJdj7LqOsKFyX/PJPriCdqoPiIsaS+kU0hgsRH/y lLOaeCodDIn9/LgyACJoBpXDxBDPsIo4wbktJEb2wJhHZ76fyY2B8ZSQD6lGy27fRMJ/ K80QM/UxatNrmUpQ1KsU38B37OzTljnj2bRfmjgp9Japhjq1Cr/1DPH+M8I4eTzFirrR MZkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tPdmfa5G; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f8si4139600ejd.270.2019.10.18.15.18.40; Fri, 18 Oct 2019 15:19:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tPdmfa5G; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503054AbfJQUmw (ORCPT + 99 others); Thu, 17 Oct 2019 16:42:52 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:35941 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2502438AbfJQUmi (ORCPT ); Thu, 17 Oct 2019 16:42:38 -0400 Received: by mail-pg1-f196.google.com with SMTP id 23so2026884pgk.3; Thu, 17 Oct 2019 13:42:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ee91/xG94vrK174Ap37BZY7hPtCqG3wuDv6y0inOwfc=; b=tPdmfa5GhJgDexdot7dFaorP9ntzYJ8XkuMaPkGiQYZXsUiaEaq13F9ak56x6kExDM t/6JYqXr8/TTdnf2vwoAAGnWG9poQ501bHa9wp3jfXSu0/KNqc7wPpsTbrJGpyv2RGs9 MgRG+LAaHdh4AxyHBxKvV85UPYJJUlPvMvktXV8VzF79jwjHa7dTKu8NWRJ3IIIrFAry cfvXqfNnmaf720tOcGV4avokQN//I6NYgyniyx7Qyi77bf6DswKdFk4V74A+I8Tu+f61 iibwv2BFy1mi9SNR/Tb1d3f96H2fzUjqfQHR8BaFooaeVG1J8gx61Rfda3ZYkaSLqbzu iIEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ee91/xG94vrK174Ap37BZY7hPtCqG3wuDv6y0inOwfc=; b=A50rwOSLaOw6Gi+y4kLzwAQyBNGC3LAOnnybpt9lxomR2abJbpbk6m1kViy6gvkhGq 83ZDEQ/BRTGyEaCIP97DEQH4CPWLsaP2Wmj02CrWroea4pUDGjKJ+K6rVfoWLR2Hya6x dz68P26meq8rO4ZRXc4vUnAMQvJNQ5OgNrIGWJLLNrp8oYva22w2tyFfSbytBm7pWGub l/PSM1nRnS/kfuP+rqe+9ff9Ks02ze6EP5WQ5+F9alwysAcTnqkMZyxoZWska78OdcUG 2fu2nyvyu0wnK6U5Z01Qc3ctUgYWhfYjkgjfL3N8XnRA0sSh8nf8FFIsfqGD7lHhHxrg fo4Q== X-Gm-Message-State: APjAAAXasom7sFxnQWaHgdTuAZL8qmkE9XcDUfvC5+DmAPMaYhesY3R+ neR8OF5wsOJo5WnyG1CwBqBQ+ELM X-Received: by 2002:a17:90a:aa97:: with SMTP id l23mr6574076pjq.7.1571344956347; Thu, 17 Oct 2019 13:42:36 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id b3sm4626365pfd.125.2019.10.17.13.42.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2019 13:42:35 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Jilayne Lovejoy , Steve Winslow , linux-kernel@vger.kernel.org Subject: [PATCH 11/22] Input: cobalt_btns - convert to use managed resources Date: Thu, 17 Oct 2019 13:42:05 -0700 Message-Id: <20191017204217.106453-12-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog In-Reply-To: <20191017204217.106453-1-dmitry.torokhov@gmail.com> References: <20191017204217.106453-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This simplifies error handling and allows to remove cobalt_buttons_remove() method. Signed-off-by: Dmitry Torokhov --- drivers/input/misc/cobalt_btns.c | 57 ++++++++++---------------------- 1 file changed, 17 insertions(+), 40 deletions(-) diff --git a/drivers/input/misc/cobalt_btns.c b/drivers/input/misc/cobalt_btns.c index bcf6174bbd5d..f7c1693fc6bb 100644 --- a/drivers/input/misc/cobalt_btns.c +++ b/drivers/input/misc/cobalt_btns.c @@ -5,6 +5,7 @@ * Copyright (C) 2007-2008 Yoichi Yuasa */ #include +#include #include #include #include @@ -26,7 +27,6 @@ static const unsigned short cobalt_map[] = { }; struct buttons_dev { - struct input_polled_dev *poll_dev; unsigned short keymap[ARRAY_SIZE(cobalt_map)]; int count[ARRAY_SIZE(cobalt_map)]; void __iomem *reg; @@ -67,15 +67,24 @@ static int cobalt_buttons_probe(struct platform_device *pdev) struct resource *res; int error, i; - bdev = kzalloc(sizeof(struct buttons_dev), GFP_KERNEL); - poll_dev = input_allocate_polled_device(); - if (!bdev || !poll_dev) { - error = -ENOMEM; - goto err_free_mem; - } + bdev = devm_kzalloc(&pdev->dev, sizeof(*bdev), GFP_KERNEL); + if (!bdev) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) + return -EBUSY; + + bdev->reg = devm_ioremap(&pdev->dev, res->start, resource_size(res)); + if (!bdev->reg) + return -ENOMEM; memcpy(bdev->keymap, cobalt_map, sizeof(bdev->keymap)); + poll_dev = devm_input_allocate_polled_device(&pdev->dev); + if (!poll_dev) + return -ENOMEM; + poll_dev->private = bdev; poll_dev->poll = handle_buttons; poll_dev->poll_interval = BUTTONS_POLL_INTERVAL; @@ -84,7 +93,6 @@ static int cobalt_buttons_probe(struct platform_device *pdev) input->name = "Cobalt buttons"; input->phys = "cobalt/input0"; input->id.bustype = BUS_HOST; - input->dev.parent = &pdev->dev; input->keycode = bdev->keymap; input->keycodemax = ARRAY_SIZE(bdev->keymap); @@ -96,39 +104,9 @@ static int cobalt_buttons_probe(struct platform_device *pdev) __set_bit(bdev->keymap[i], input->keybit); __clear_bit(KEY_RESERVED, input->keybit); - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) { - error = -EBUSY; - goto err_free_mem; - } - - bdev->poll_dev = poll_dev; - bdev->reg = ioremap(res->start, resource_size(res)); - dev_set_drvdata(&pdev->dev, bdev); - error = input_register_polled_device(poll_dev); if (error) - goto err_iounmap; - - return 0; - - err_iounmap: - iounmap(bdev->reg); - err_free_mem: - input_free_polled_device(poll_dev); - kfree(bdev); - return error; -} - -static int cobalt_buttons_remove(struct platform_device *pdev) -{ - struct device *dev = &pdev->dev; - struct buttons_dev *bdev = dev_get_drvdata(dev); - - input_unregister_polled_device(bdev->poll_dev); - input_free_polled_device(bdev->poll_dev); - iounmap(bdev->reg); - kfree(bdev); + return error; return 0; } @@ -141,7 +119,6 @@ MODULE_ALIAS("platform:Cobalt buttons"); static struct platform_driver cobalt_buttons_driver = { .probe = cobalt_buttons_probe, - .remove = cobalt_buttons_remove, .driver = { .name = "Cobalt buttons", }, -- 2.23.0.866.gb869b98d4c-goog