From patchwork Fri Aug 15 18:16:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Frank_Sch=C3=A4fer?= X-Patchwork-Id: 4728971 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 4F0A39F38D for ; Fri, 15 Aug 2014 18:15:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 58C392016C for ; Fri, 15 Aug 2014 18:15:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7A49C2013D for ; Fri, 15 Aug 2014 18:15:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751122AbaHOSPx (ORCPT ); Fri, 15 Aug 2014 14:15:53 -0400 Received: from mail-lb0-f181.google.com ([209.85.217.181]:36257 "EHLO mail-lb0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751027AbaHOSPx (ORCPT ); Fri, 15 Aug 2014 14:15:53 -0400 Received: by mail-lb0-f181.google.com with SMTP id 10so2251003lbg.12 for ; Fri, 15 Aug 2014 11:15:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=+NTfV6C2u2CLAidtQd0+wXnVeClFtScQBY5ayEVOdm0=; b=RzPTdhsUJFrDvi4rjG3I3L1ZbJysdoUVziEEKAzNfkXaZz2fHSKzPZPR7dobzH22XY u2BTz83MO1rrP3UdeGM3pdINIQLko3/vsuvBpDA/O3NeJnIgJibsMsgRla4lAKBc0qJ6 5NSc3Or4sMw3BLLEq9rB5GZe7dAIQolfrXsB5Y77rdrkyWtBy98Gwk+ZnU1IsPJLW21e L3MLGC3fpyx9BQQDCFirdA1O0/M1Xv3DRGeosZgEvspGuIUOFxBZ0bk+hDemnQaBgE/s Lp9gacT8AW+oBL1Bji7I9Np19BHa7tFaPOcmRIghRcIZY7FRB2NqeYD9iDO1iI9X6MSk 9tbg== X-Received: by 10.152.203.232 with SMTP id kt8mr13281323lac.27.1408126551699; Fri, 15 Aug 2014 11:15:51 -0700 (PDT) Received: from Athlon64X2-5000.lan (ip-109-91-212-140.hsi12.unitymediagroup.de. [109.91.212.140]) by mx.google.com with ESMTPSA id jf2sm13734338lbc.34.2014.08.15.11.15.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Aug 2014 11:15:50 -0700 (PDT) From: =?UTF-8?q?Frank=20Sch=C3=A4fer?= To: m.chehab@samsung.com Cc: hverkuil@xs4all.nl, linux-media@vger.kernel.org, =?UTF-8?q?Frank=20Sch=C3=A4fer?= Subject: [PATCH] em28xx-input: i2c IR decoders: improve i2c_client handling Date: Fri, 15 Aug 2014 20:16:58 +0200 Message-Id: <1408126618-4043-1-git-send-email-fschaefer.oss@googlemail.com> X-Mailer: git-send-email 1.8.4.5 MIME-Version: 1.0 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.5 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 Instead of using a temporary stack allocated i2c_client in em28xx_i2c_ir_handle_key(), allocate/free the i2c_client at module init/uninit and hook it into struct em28xx_IR (if the device has an i2c IR decoder). This reduces the frame size of function em28xx_i2c_ir_handle_key() and speeds it up a bit. Also make sure that all fields of struct i2c_client are initialized properly. Signed-off-by: Frank Schäfer --- drivers/media/usb/em28xx/em28xx-input.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/media/usb/em28xx/em28xx-input.c b/drivers/media/usb/em28xx/em28xx-input.c index ed843bd..962446a 100644 --- a/drivers/media/usb/em28xx/em28xx-input.c +++ b/drivers/media/usb/em28xx/em28xx-input.c @@ -71,8 +71,7 @@ struct em28xx_IR { unsigned int last_readcount; u64 rc_type; - /* i2c slave address of external device (if used) */ - u16 i2c_dev_addr; + struct i2c_client *i2c_client; int (*get_key_i2c)(struct i2c_client *ir, enum rc_type *protocol, u32 *scancode); int (*get_key)(struct em28xx_IR *, struct em28xx_ir_poll_result *); @@ -294,16 +293,11 @@ static int em2874_polling_getkey(struct em28xx_IR *ir, static int em28xx_i2c_ir_handle_key(struct em28xx_IR *ir) { - struct em28xx *dev = ir->dev; static u32 scancode; enum rc_type protocol; int rc; - struct i2c_client client; - - client.adapter = &ir->dev->i2c_adap[dev->def_i2c_bus]; - client.addr = ir->i2c_dev_addr; - rc = ir->get_key_i2c(&client, &protocol, &scancode); + rc = ir->get_key_i2c(ir->i2c_client, &protocol, &scancode); if (rc < 0) { dprintk("ir->get_key_i2c() failed: %d\n", rc); return rc; @@ -361,7 +355,7 @@ static void em28xx_ir_work(struct work_struct *work) { struct em28xx_IR *ir = container_of(work, struct em28xx_IR, work.work); - if (ir->i2c_dev_addr) /* external i2c device */ + if (ir->i2c_client) /* external i2c device */ em28xx_i2c_ir_handle_key(ir); else /* internal device */ em28xx_ir_handle_key(ir); @@ -756,7 +750,13 @@ static int em28xx_ir_init(struct em28xx *dev) goto error; } - ir->i2c_dev_addr = i2c_rc_dev_addr; + ir->i2c_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); + if (!ir->i2c_client) + goto error; + ir->i2c_client->adapter = &ir->dev->i2c_adap[dev->def_i2c_bus]; + ir->i2c_client->addr = i2c_rc_dev_addr; + ir->i2c_client->flags = 0; + /* NOTE: all other fields of i2c_client are unused */ } else { /* internal device */ switch (dev->chip_id) { case CHIP_ID_EM2860: @@ -815,6 +815,7 @@ static int em28xx_ir_init(struct em28xx *dev) return 0; error: + kfree(ir->i2c_client); dev->ir = NULL; rc_free_device(rc); kfree(ir); @@ -841,6 +842,8 @@ static int em28xx_ir_fini(struct em28xx *dev) if (ir->rc) rc_unregister_device(ir->rc); + kfree(ir->i2c_client); + /* done */ kfree(ir); dev->ir = NULL;