From patchwork Thu May 18 20:08:38 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: 9735235 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 6FC8B6022E for ; Thu, 18 May 2017 20:38:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59F5528905 for ; Thu, 18 May 2017 20:38:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4EF58288D0; Thu, 18 May 2017 20:38:14 +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 05053288CF for ; Thu, 18 May 2017 20:38:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755680AbdERUiA (ORCPT ); Thu, 18 May 2017 16:38:00 -0400 Received: from gateway23.websitewelcome.com ([192.185.49.219]:23223 "EHLO gateway23.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755643AbdERUh7 (ORCPT ); Thu, 18 May 2017 16:37:59 -0400 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway23.websitewelcome.com (Postfix) with ESMTP id D33E01AAE0 for ; Thu, 18 May 2017 15:08:38 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id BRjCdv0xPri87BRjCdZliT; Thu, 18 May 2017 15:08:54 -0500 Received: from gator4166.hostgator.com ([108.167.133.22]:14970) by gator4166.hostgator.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.87) (envelope-from ) id 1dBRiw-000W1w-IX; Thu, 18 May 2017 15:08:38 -0500 Received: from 189.152.179.187 ([189.152.179.187]) by gator4166.hostgator.com (Horde Framework) with HTTPS; Thu, 18 May 2017 15:08:38 -0500 Date: Thu, 18 May 2017 15:08:38 -0500 Message-ID: <20170518150838.Horde.QcvULS7zHP-s_vp5WQpCBSD@gator4166.hostgator.com> From: "Gustavo A. R. Silva" To: Malcolm Priestley Cc: Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [media-dvb-usb-v2] question about value overwrite References: <20170518140901.Horde.bHPlhISMuTRMEbVjfq3p1kd@gator4166.hostgator.com> <00672b5e-4cf2-e271-80c1-af5c406cdb09@gmail.com> In-Reply-To: <00672b5e-4cf2-e271-80c1-af5c406cdb09@gmail.com> 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: 1dBRiw-000W1w-IX X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: gator4166.hostgator.com [108.167.133.22]:14970 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 Hi Malcolm, Quoting Malcolm Priestley : > Hi > > On 18/05/17 20:09, Gustavo A. R. Silva wrote: >> >> Hello everybody, >> >> While looking into Coverity ID 1226934 I ran into the following >> piece of code at drivers/media/usb/dvb-usb-v2/lmedm04.c:205 >> >> 205static int lme2510_stream_restart(struct dvb_usb_device *d) >> 206{ >> 207 struct lme2510_state *st = d->priv; >> 208 u8 all_pids[] = LME_ALL_PIDS; >> 209 u8 stream_on[] = LME_ST_ON_W; >> 210 int ret; >> 211 u8 rbuff[1]; >> 212 if (st->pid_off) >> 213 ret = lme2510_usb_talk(d, all_pids, sizeof(all_pids), >> 214 rbuff, sizeof(rbuff)); >> 215 /*Restart Stream Command*/ >> 216 ret = lme2510_usb_talk(d, stream_on, sizeof(stream_on), >> 217 rbuff, sizeof(rbuff)); >> 218 return ret; >> 219} > > It is a mistake it should have been ORed ad in |= as > lme2510_usb_talk only returns three states. > I see now. The idea is to code something similar to the following piece of code in the same file: 242 243 ret |= lme2510_usb_talk(d, pid_buff , 244 sizeof(pid_buff) , rbuf, sizeof(rbuf)); 245 246 if (st->stream_on) 247 ret |= lme2510_stream_restart(d); 248 249 return ret; right? So in this case, the following patch would properly fix the bug: index 924adfd..3ab1754 100644 } What do you think? > So if an error is in the running it will be returned to user. > > The first of your patches is better and more or less the same, the > second would break driver, restart is not an else condition. > Thank you for the clarification. --- Gustavo A. R. Silva --- a/drivers/media/usb/dvb-usb-v2/lmedm04.c +++ b/drivers/media/usb/dvb-usb-v2/lmedm04.c @@ -207,13 +207,14 @@ static int lme2510_stream_restart(struct dvb_usb_device *d) struct lme2510_state *st = d->priv; u8 all_pids[] = LME_ALL_PIDS; u8 stream_on[] = LME_ST_ON_W; - int ret; + int ret = 0; u8 rbuff[1]; + if (st->pid_off) ret = lme2510_usb_talk(d, all_pids, sizeof(all_pids), rbuff, sizeof(rbuff)); /*Restart Stream Command*/ - ret = lme2510_usb_talk(d, stream_on, sizeof(stream_on), + ret |= lme2510_usb_talk(d, stream_on, sizeof(stream_on), rbuff, sizeof(rbuff)); return ret;