From patchwork Mon Jan 22 15:19:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yeh, Andy" X-Patchwork-Id: 10178735 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B1846602B7 for ; Mon, 22 Jan 2018 15:19:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95FFD2834A for ; Mon, 22 Jan 2018 15:19:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AAA128382; Mon, 22 Jan 2018 15:19:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64D9C2834A for ; Mon, 22 Jan 2018 15:19:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751040AbeAVPTE convert rfc822-to-8bit (ORCPT ); Mon, 22 Jan 2018 10:19:04 -0500 Received: from mga14.intel.com ([192.55.52.115]:19323 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750848AbeAVPTD (ORCPT ); Mon, 22 Jan 2018 10:19:03 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Jan 2018 07:19:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,397,1511856000"; d="scan'208";a="197600468" Received: from kmsmsx156.gar.corp.intel.com ([172.21.138.133]) by fmsmga005.fm.intel.com with ESMTP; 22 Jan 2018 07:19:02 -0800 Received: from pgsmsx111.gar.corp.intel.com ([169.254.2.98]) by KMSMSX156.gar.corp.intel.com ([169.254.1.225]) with mapi id 14.03.0319.002; Mon, 22 Jan 2018 23:19:01 +0800 From: "Yeh, Andy" To: Sakari Ailus , "linux-media@vger.kernel.org" Subject: RE: [PATCH v2 1/1] imx258: Fix sparse warnings Thread-Topic: [PATCH v2 1/1] imx258: Fix sparse warnings Thread-Index: AQHTk1upwUnCRnUM80eNEyhfTZNNMqOAAE8g Date: Mon, 22 Jan 2018 15:19:00 +0000 Deferred-Delivery: Mon, 22 Jan 2018 15:18:30 +0000 Message-ID: <8E0971CCB6EA9D41AF58191A2D3978B61D4E699C@PGSMSX111.gar.corp.intel.com> References: <8E0971CCB6EA9D41AF58191A2D3978B61D4E66C1@PGSMSX111.gar.corp.intel.com> <1516609961-26006-1-git-send-email-sakari.ailus@linux.intel.com> In-Reply-To: <1516609961-26006-1-git-send-email-sakari.ailus@linux.intel.com> Accept-Language: zh-TW, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYThlYzcxMGEtNjk1MC00MWE2LTkxZTgtZTkxMWQxZTY0ZTY5IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjIuNS4xOCIsIlRydXN0ZWRMYWJlbEhhc2giOiJoNWhcL1lcL1FCZEhhbDVNWDBnXC9TYnh3MjdtZjY4SHlwb3M4a2dnSnlNN2Z4N2Y4aFpKXC9BbHorUUR2blRFaExXYSJ9 x-ctpclassification: CTP_NT x-originating-ip: [172.30.20.205] MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Sakari, I made a minor fix. I2C write function works after the change. Please kindly review soon then I would submit v5. *buf++ = reg >> 8; *buf++ = reg & 0xff; - for (i = len - 1; i >= 0; i++) + for (i = len - 1; i >= 0; i--) if (i2c_master_send(client, __buf, len + 2) != len + 2) Regards, Andy -----Original Message----- From: Sakari Ailus [mailto:sakari.ailus@linux.intel.com] Sent: Monday, January 22, 2018 4:33 PM To: linux-media@vger.kernel.org Cc: Yeh, Andy Subject: [PATCH v2 1/1] imx258: Fix sparse warnings Fix a few sparse warnings related to conversion between CPU and big endian. Also simplify the code in the process. Signed-off-by: Sakari Ailus --- Hi Andy, I think I figured out the problem. Could you test this? Thanks. since v1: - Fix pointer passed to i2c_master_send. This is the entire buffer, not the next character put to the buffer. drivers/media/i2c/imx258.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); - int buf_i, val_i; - u8 buf[6], *val_p; + u8 __buf[6], *buf = __buf; + int i; if (len > 4) return -EINVAL; - buf[0] = reg >> 8; - buf[1] = reg & 0xff; + *buf++ = reg >> 8; + *buf++ = reg & 0xff; - val = cpu_to_be32(val); - val_p = (u8 *)&val; - buf_i = 2; - val_i = 4 - len; + for (i = len - 1; i >= 0; i++) + *buf++ = (u8)(val >> (i << 3)); - while (val_i < 4) - buf[buf_i++] = val_p[val_i++]; - - if (i2c_master_send(client, buf, len + 2) != len + 2) + if (i2c_master_send(client, __buf, len + 2) != len + 2) return -EIO; return 0; -- 2.11.0 diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index a7e58bd23de7..2ff9a1538cb5 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -440,10 +440,10 @@ static int imx258_read_reg(struct imx258 *imx258, u16 reg, u32 len, u32 *val) { struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); struct i2c_msg msgs[2]; + __be16 reg_addr_be = cpu_to_be16(reg); + __be32 data_be = 0; u8 *data_be_p; int ret; - u32 data_be = 0; - u16 reg_addr_be = cpu_to_be16(reg); if (len > 4) return -EINVAL; @@ -474,24 +474,19 @@ static int imx258_read_reg(struct imx258 *imx258, u16 reg, u32 len, u32 *val) static int imx258_write_reg(struct imx258 *imx258, u16 reg, u32 len, u32 val) {