From patchwork Mon Apr 23 12:29:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10356901 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 00AB6601D3 for ; Mon, 23 Apr 2018 12:29:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3DE328A96 for ; Mon, 23 Apr 2018 12:29:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D729B28A9F; Mon, 23 Apr 2018 12:29:16 +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.4 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,URIBL_RHS_DOB 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 ECF1C28A96 for ; Mon, 23 Apr 2018 12:29:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754820AbeDWM3O (ORCPT ); Mon, 23 Apr 2018 08:29:14 -0400 Received: from osg.samsung.com ([64.30.133.232]:62829 "EHLO osg.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754729AbeDWM3N (ORCPT ); Mon, 23 Apr 2018 08:29:13 -0400 Received: from localhost (localhost [127.0.0.1]) by osg.samsung.com (Postfix) with ESMTP id 463053DBAB; Mon, 23 Apr 2018 05:29:13 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at dev.s-opensource.com Received: from osg.samsung.com ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 95c7rdCU5D68; Mon, 23 Apr 2018 05:29:12 -0700 (PDT) Received: from smtp.s-opensource.com (177.18.30.209.dynamic.adsl.gvt.net.br [177.18.30.209]) by osg.samsung.com (Postfix) with ESMTPSA id F14D63DBA3; Mon, 23 Apr 2018 05:29:11 -0700 (PDT) Received: from mchehab by smtp.s-opensource.com with local (Exim 4.90_1) (envelope-from ) id 1fAaaj-00033e-Lh; Mon, 23 Apr 2018 08:29:09 -0400 From: Mauro Carvalho Chehab Cc: Mauro Carvalho Chehab , Linux Media Mailing List , Mauro Carvalho Chehab , Philippe Ombredanne , Greg Kroah-Hartman , Kate Stewart , Thomas Gleixner Subject: [PATCH] media: flexcop-i2c: get rid of KERN_CONT Date: Mon, 23 Apr 2018 08:29:09 -0400 Message-Id: X-Mailer: git-send-email 2.14.3 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-Virus-Scanned: ClamAV using ClamSMTP Coverity complains about werid stuff at the debug logic: CID 113542 (#1 of 1): Out-of-bounds access (ARRAY_VS_SINGLETON)10. callee_ptr_arith: Passing buf to function flexcop_i2c_write4 which uses it as an array. This might corrupt or misinterpret adjacent memory locations. Instead of directly addressing the issue there, let's rework at the logic there. On newer kernels, KERN_CONT does nothing, as the previous message won't wait for a continuation. Also, both flexcop_i2c_read4() and flexcop_i2c_write4(), called by it, will print stuff if (debug &4). So, the way it is is too buggy. There are two kinds of debug stuff there: deb_i2c() and a code hidden under #ifdef DUMP_I2C_MESSAGES, with can't be selected without touching the source code. Also, if both debug & 0x4 and DUMP_I2C_MESSAGES, flexcop_i2c_request() will emit two debug messages per call with different data, with sounds messy. Simplify it by getting rid of DUMP_I2C_MESSAGES and adding a new flag to debug (0x40), and making the debug logic there more consistent. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/common/b2c2/flexcop-i2c.c | 47 +++++++++++++-------------------- drivers/media/common/b2c2/flexcop.c | 2 +- drivers/media/common/b2c2/flexcop.h | 1 + 3 files changed, 21 insertions(+), 29 deletions(-) diff --git a/drivers/media/common/b2c2/flexcop-i2c.c b/drivers/media/common/b2c2/flexcop-i2c.c index 564da6fa900d..db2f3b19abf7 100644 --- a/drivers/media/common/b2c2/flexcop-i2c.c +++ b/drivers/media/common/b2c2/flexcop-i2c.c @@ -105,40 +105,36 @@ static int flexcop_i2c_write4(struct flexcop_device *fc, } int flexcop_i2c_request(struct flexcop_i2c_adapter *i2c, - flexcop_access_op_t op, u8 chipaddr, u8 addr, u8 *buf, u16 len) + flexcop_access_op_t op, u8 chipaddr, + u8 start_addr, u8 *buf, u16 size) { int ret; - -#ifdef DUMP_I2C_MESSAGES - int i; -#endif + int len = size; + u8 *p; + u8 addr = start_addr; u16 bytes_to_transfer; flexcop_ibi_value r100; - deb_i2c("op = %d\n",op); + deb_i2c("port %d %s(%02x): register %02x, size: %d\n", + i2c->port, + op == FC_READ ? "rd" : "wr", + chipaddr, start_addr, size); r100.raw = 0; r100.tw_sm_c_100.chipaddr = chipaddr; r100.tw_sm_c_100.twoWS_rw = op; r100.tw_sm_c_100.twoWS_port_reg = i2c->port; -#ifdef DUMP_I2C_MESSAGES - printk(KERN_DEBUG "%d ", i2c->port); - if (op == FC_READ) - printk(KERN_CONT "rd("); - else - printk(KERN_CONT "wr("); - printk(KERN_CONT "%02x): %02x ", chipaddr, addr); -#endif - /* in that case addr is the only value -> * we write it twice as baseaddr and val0 * BBTI is doing it like that for ISL6421 at least */ if (i2c->no_base_addr && len == 0 && op == FC_WRITE) { - buf = &addr; + buf = &start_addr; len = 1; } + p = buf; + while (len != 0) { bytes_to_transfer = len > 4 ? 4 : len; @@ -146,26 +142,21 @@ int flexcop_i2c_request(struct flexcop_i2c_adapter *i2c, r100.tw_sm_c_100.baseaddr = addr; if (op == FC_READ) - ret = flexcop_i2c_read4(i2c, r100, buf); + ret = flexcop_i2c_read4(i2c, r100, p); else - ret = flexcop_i2c_write4(i2c->fc, r100, buf); - -#ifdef DUMP_I2C_MESSAGES - for (i = 0; i < bytes_to_transfer; i++) - printk(KERN_CONT "%02x ", buf[i]); -#endif + ret = flexcop_i2c_write4(i2c->fc, r100, p); if (ret < 0) return ret; - buf += bytes_to_transfer; + p += bytes_to_transfer; addr += bytes_to_transfer; len -= bytes_to_transfer; } - -#ifdef DUMP_I2C_MESSAGES - printk(KERN_CONT "\n"); -#endif + deb_i2c_dump("port %d %s(%02x): register %02x: %*ph\n", + i2c->port, + op == FC_READ ? "rd" : "wr", + chipaddr, start_addr, size, buf); return 0; } diff --git a/drivers/media/common/b2c2/flexcop.c b/drivers/media/common/b2c2/flexcop.c index 2e0ab55cd67e..cbaa61f10d5f 100644 --- a/drivers/media/common/b2c2/flexcop.c +++ b/drivers/media/common/b2c2/flexcop.c @@ -42,7 +42,7 @@ int b2c2_flexcop_debug; EXPORT_SYMBOL_GPL(b2c2_flexcop_debug); module_param_named(debug, b2c2_flexcop_debug, int, 0644); MODULE_PARM_DESC(debug, - "set debug level (1=info,2=tuner,4=i2c,8=ts,16=sram,32=reg (|-able))." + "set debug level (1=info,2=tuner,4=i2c,8=ts,16=sram,32=reg,64=i2cdump (|-able))." DEBSTATUS); #undef DEBSTATUS diff --git a/drivers/media/common/b2c2/flexcop.h b/drivers/media/common/b2c2/flexcop.h index 911ece59ea02..486fe2380b92 100644 --- a/drivers/media/common/b2c2/flexcop.h +++ b/drivers/media/common/b2c2/flexcop.h @@ -26,5 +26,6 @@ extern int b2c2_flexcop_debug; #define deb_ts(args...) dprintk(0x08, args) #define deb_sram(args...) dprintk(0x10, args) #define deb_rdump(args...) dprintk(0x20, args) +#define deb_i2c_dump(args...) dprintk(0x40, args) #endif