From patchwork Thu May 18 22:07:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 9735345 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 F3CE8600CC for ; Thu, 18 May 2017 22:30:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFBF72845E for ; Thu, 18 May 2017 22:30:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D43FD288D2; Thu, 18 May 2017 22:30:08 +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=-5.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_NUMERIC_HELO autolearn=unavailable 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 8C1CB2845E for ; Thu, 18 May 2017 22:30:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755751AbdERWaG (ORCPT ); Thu, 18 May 2017 18:30:06 -0400 Received: from gateway33.websitewelcome.com ([192.185.145.4]:47328 "EHLO gateway33.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755577AbdERWaG (ORCPT ); Thu, 18 May 2017 18:30:06 -0400 X-Greylist: delayed 1373 seconds by postgrey-1.27 at vger.kernel.org; Thu, 18 May 2017 18:30:06 EDT Received: from cm4.websitewelcome.com (unknown [108.167.139.16]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 8594016273 for ; Thu, 18 May 2017 17:07:10 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cm4.websitewelcome.com with id My791v00l0V9LXg01y7AwQ; Thu, 18 May 2017 17:07:10 -0500 Received: from gator4166.hostgator.com ([108.167.133.22]:42387) by gator4166.hostgator.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.87) (envelope-from ) id 1dBTZd-000Evf-An; Thu, 18 May 2017 17:07:09 -0500 Received: from 189.152.179.187 ([189.152.179.187]) by gator4166.hostgator.com (Horde Framework) with HTTPS; Thu, 18 May 2017 17:07:09 -0500 Date: Thu, 18 May 2017 17:07:09 -0500 Message-ID: <20170518170709.Horde.zKHvDFB0L61Od1t7GtHytpR@gator4166.hostgator.com> From: "Gustavo A. R. Silva" To: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [media-pci-cx25821] question about value overwrite User-Agent: Horde Application Framework 5 MIME-Version: 1.0 Content-Disposition: inline X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 108.167.133.22 X-Exim-ID: 1dBTZd-000Evf-An X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: gator4166.hostgator.com [108.167.133.22]:42387 X-Source-Auth: garsilva@embeddedor.com X-Email-Count: 2 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= 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 Hello everybody, While looking into Coverity ID 1226903 I ran into the following piece of code at drivers/media/pci/cx25821/cx25821-medusa-video.c:393: 393int medusa_set_videostandard(struct cx25821_dev *dev) 394{ 395 int status = 0; 396 u32 value = 0, tmp = 0; 397 398 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK) 399 status = medusa_initialize_pal(dev); 400 else 401 status = medusa_initialize_ntsc(dev); 402 403 /* Enable DENC_A output */ 404 value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_A_REG_4, &tmp); 405 value = setBitAtPos(value, 4); 406 status = cx25821_i2c_write(&dev->i2c_bus[0], DENC_A_REG_4, value); 407 408 /* Enable DENC_B output */ 409 value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_B_REG_4, &tmp); 410 value = setBitAtPos(value, 4); 411 status = cx25821_i2c_write(&dev->i2c_bus[0], DENC_B_REG_4, value); 412 413 return status; 414} The issue is that the value stored in variable _status_ at lines 399 and 401 is overwritten by the one stored at line 406 and then at line 411, before it can be used. My question is if the original intention was to ORed the return values, something like in the following patch: index 0a9db05..226d14f 100644 What do you think? I'd really appreciate any comment on this. Thank you! --- Gustavo A. R. Silva --- a/drivers/media/pci/cx25821/cx25821-medusa-video.c +++ b/drivers/media/pci/cx25821/cx25821-medusa-video.c @@ -403,12 +403,12 @@ int medusa_set_videostandard(struct cx25821_dev *dev) /* Enable DENC_A output */ value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_A_REG_4, &tmp); value = setBitAtPos(value, 4); - status = cx25821_i2c_write(&dev->i2c_bus[0], DENC_A_REG_4, value); + status |= cx25821_i2c_write(&dev->i2c_bus[0], DENC_A_REG_4, value); /* Enable DENC_B output */ value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_B_REG_4, &tmp); value = setBitAtPos(value, 4); - status = cx25821_i2c_write(&dev->i2c_bus[0], DENC_B_REG_4, value); + status |= cx25821_i2c_write(&dev->i2c_bus[0], DENC_B_REG_4, value); return status; }