From patchwork Tue Jan 14 19:27:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 3488381 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9FB849F2E9 for ; Tue, 14 Jan 2014 22:31:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C36242021C for ; Tue, 14 Jan 2014 22:31:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3E1AD2024F for ; Tue, 14 Jan 2014 22:31:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751811AbaANWbn (ORCPT ); Tue, 14 Jan 2014 17:31:43 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:57283 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751736AbaANWbl (ORCPT ); Tue, 14 Jan 2014 17:31:41 -0500 Received: from [177.143.150.208] (helo=smtp.w2.samsung.com) by bombadil.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1W3CWI-00064W-7j; Tue, 14 Jan 2014 22:31:38 +0000 Received: from mchehab by smtp.w2.samsung.com with local (Exim 4.80.1) (envelope-from ) id 1W39eW-0006Ax-S1; Tue, 14 Jan 2014 17:27:56 -0200 From: Mauro Carvalho Chehab Cc: Mauro Carvalho Chehab , Linux Media Mailing List , Mauro Carvalho Chehab Subject: [PATCH] [media] rc-core: reuse device numbers Date: Tue, 14 Jan 2014 17:27:55 -0200 Message-Id: <1389727675-23705-1-git-send-email-m.chehab@samsung.com> X-Mailer: git-send-email 1.8.3.1 To: unlisted-recipients:; (no To-header on input) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Before changeset d8b4b5822f51e, the remote controller device numbers were released when the device were unregistered. That helped to maintain some sanity, as, when USB devices are replugged, the remote controller would get the same number. Restore the same behaviour. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/rc/rc-main.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c index 46da365c9c84..02e2f38c9c85 100644 --- a/drivers/media/rc/rc-main.c +++ b/drivers/media/rc/rc-main.c @@ -22,6 +22,10 @@ #include #include "rc-core-priv.h" +/* Bitmap to store allocated device numbers from 0 to IRRCV_NUM_DEVICES - 1 */ +#define IRRCV_NUM_DEVICES 256 +DECLARE_BITMAP(ir_core_dev_number, IRRCV_NUM_DEVICES); + /* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */ #define IR_TAB_MIN_SIZE 256 #define IR_TAB_MAX_SIZE 8192 @@ -1065,10 +1069,9 @@ EXPORT_SYMBOL_GPL(rc_free_device); int rc_register_device(struct rc_dev *dev) { static bool raw_init = false; /* raw decoders loaded? */ - static atomic_t devno = ATOMIC_INIT(0); struct rc_map *rc_map; const char *path; - int rc; + int rc, devno; if (!dev || !dev->map_name) return -EINVAL; @@ -1096,7 +1099,15 @@ int rc_register_device(struct rc_dev *dev) */ mutex_lock(&dev->lock); - dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1); + do { + devno = find_first_zero_bit(ir_core_dev_number, + IRRCV_NUM_DEVICES); + /* No free device slots */ + if (devno >= IRRCV_NUM_DEVICES) + return -ENOMEM; + } while (test_and_set_bit(devno, ir_core_dev_number)); + + dev->devno = devno; dev_set_name(&dev->dev, "rc%ld", dev->devno); dev_set_drvdata(&dev->dev, dev); rc = device_add(&dev->dev); @@ -1186,6 +1197,7 @@ out_dev: device_del(&dev->dev); out_unlock: mutex_unlock(&dev->lock); + clear_bit(dev->devno, ir_core_dev_number); return rc; } EXPORT_SYMBOL_GPL(rc_register_device); @@ -1197,6 +1209,8 @@ void rc_unregister_device(struct rc_dev *dev) del_timer_sync(&dev->timer_keyup); + clear_bit(dev->devno, ir_core_dev_number); + if (dev->driver_type == RC_DRIVER_IR_RAW) ir_raw_event_unregister(dev);