From patchwork Tue Aug 21 16:12:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antti Palosaari X-Patchwork-Id: 1356461 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 32D223FC81 for ; Tue, 21 Aug 2012 16:13:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753068Ab2HUQNO (ORCPT ); Tue, 21 Aug 2012 12:13:14 -0400 Received: from mail.kapsi.fi ([217.30.184.167]:40933 "EHLO mail.kapsi.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757904Ab2HUQNM (ORCPT ); Tue, 21 Aug 2012 12:13:12 -0400 Received: from dyn2-212-50-134-229.psoas.suomi.net ([212.50.134.229] helo=localhost.localdomain) by mail.kapsi.fi with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1T3r4p-0005ts-El; Tue, 21 Aug 2012 19:13:11 +0300 From: Antti Palosaari To: linux-media@vger.kernel.org Cc: Antti Palosaari Subject: [PATCH 2/2] tda18218: re-implement tda18218_wr_regs() Date: Tue, 21 Aug 2012 19:12:50 +0300 Message-Id: <1345565570-30887-2-git-send-email-crope@iki.fi> X-Mailer: git-send-email 1.7.11.4 In-Reply-To: <1345565570-30887-1-git-send-email-crope@iki.fi> References: <1345565570-30887-1-git-send-email-crope@iki.fi> X-SA-Exim-Connect-IP: 212.50.134.229 X-SA-Exim-Mail-From: crope@iki.fi X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Old i2c message length splitting logic was faulty. Make it better. Signed-off-by: Antti Palosaari --- drivers/media/tuners/tda18218.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/media/tuners/tda18218.c b/drivers/media/tuners/tda18218.c index ffbec9e..1819853 100644 --- a/drivers/media/tuners/tda18218.c +++ b/drivers/media/tuners/tda18218.c @@ -23,8 +23,8 @@ /* write multiple registers */ static int tda18218_wr_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len) { - int ret = 0; - u8 buf[1+len], quotient, remainder, i, msg_len, msg_len_max; + int ret = 0, len2, remaining; + u8 buf[1 + len]; struct i2c_msg msg[1] = { { .addr = priv->cfg->i2c_address, @@ -33,17 +33,15 @@ static int tda18218_wr_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len) } }; - msg_len_max = priv->cfg->i2c_wr_max - 1; - quotient = len / msg_len_max; - remainder = len % msg_len_max; - msg_len = msg_len_max; - for (i = 0; (i <= quotient && remainder); i++) { - if (i == quotient) /* set len of the last msg */ - msg_len = remainder; - - msg[0].len = msg_len + 1; - buf[0] = reg + i * msg_len_max; - memcpy(&buf[1], &val[i * msg_len_max], msg_len); + for (remaining = len; remaining > 0; + remaining -= (priv->cfg->i2c_wr_max - 1)) { + len2 = remaining; + if (len2 > (priv->cfg->i2c_wr_max - 1)) + len2 = (priv->cfg->i2c_wr_max - 1); + + msg[0].len = 1 + len2; + buf[0] = reg + len - remaining; + memcpy(&buf[1], &val[len - remaining], len2); ret = i2c_transfer(priv->i2c, msg, 1); if (ret != 1)