From patchwork Thu Mar 27 01:13:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenyou Yang X-Patchwork-Id: 3896071 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 361129F2E8 for ; Thu, 27 Mar 2014 01:13:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5610E20213 for ; Thu, 27 Mar 2014 01:13:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6EC6C2021F for ; Thu, 27 Mar 2014 01:13:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755903AbaC0BNw (ORCPT ); Wed, 26 Mar 2014 21:13:52 -0400 Received: from nasmtp02.atmel.com ([204.2.163.16]:27644 "EHLO SJOEDG01.corp.atmel.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754369AbaC0BNv convert rfc822-to-8bit (ORCPT ); Wed, 26 Mar 2014 21:13:51 -0400 Received: from apsmtp01.atmel.com (10.168.254.30) by sjoedg01.corp.atmel.com (10.64.253.30) with Microsoft SMTP Server (TLS) id 14.2.347.0; Wed, 26 Mar 2014 18:13:23 -0700 Received: from PENCHT02.corp.atmel.com (10.168.5.162) by apsmtp01.corp.atmel.com (10.168.254.30) with Microsoft SMTP Server (TLS) id 14.2.347.0; Thu, 27 Mar 2014 09:20:30 +0800 Received: from PENMBX01.corp.atmel.com ([10.168.5.210]) by PENCHT02.corp.atmel.com ([fe80::7915:fc2e:c9a6:c45d%12]) with mapi id 14.02.0342.003; Thu, 27 Mar 2014 09:13:33 +0800 From: "Yang, Wenyou" To: Axel Lin , Mark Brown CC: linux-spi Subject: RE: [PATCH] spi: atmel: Fix test unsigned var < 0 Thread-Topic: [PATCH] spi: atmel: Fix test unsigned var < 0 Thread-Index: AQHPRdvKxrNI4eq+BUqsHdX5Ywj3KprzFYOAgACEjwCAAItcYA== Date: Thu, 27 Mar 2014 01:13:32 +0000 Message-ID: References: <1395498809.16958.1.camel@phoenix> <20140326165145.GD14287@sirena.org.uk> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.168.5.13] MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP > -----Original Message----- > From: Axel Lin [mailto:axel.lin@ingics.com] > Sent: Thursday, March 27, 2014 8:46 AM > To: Mark Brown > Cc: Yang, Wenyou; linux-spi > Subject: Re: [PATCH] spi: atmel: Fix test unsigned var < 0 > > 2014-03-27 0:51 GMT+08:00 Mark Brown : > > On Sat, Mar 22, 2014 at 10:33:29PM +0800, Axel Lin wrote: > >> current_remaining_bytes is an unsigned long and cannot be below 0. > > > >> - if (xfer->bits_per_word > 8) { > >> + > >> + if (xfer->bits_per_word > 8) > >> as->current_remaining_bytes -= 2; > >> - if (as->current_remaining_bytes < 0) > >> - as->current_remaining_bytes = 0; > >> - } else { > >> + else > >> as->current_remaining_bytes--; > >> - } > > > > This removes an error check in the case that we set the remaining > > bytes to -1. The length validation the core does should ensure that > > never happens but it seems wrong to just ignore that - we should at > > least note in the changelog that the analysis has been done. > I thought it never happen and there is no bug report for this so it's > safe with this patch. > > > > > Are you sure that the best fix isn't to just use an int here? > Wenyou, > Any comments for this? Like Mark said, It seems it is more reasonable using a signed int, instead of unsigned int. -->8 --- --<8 --- Best Regards, Wenyou Yang --- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c index 8005f98..485e6cc 100644 --- a/drivers/spi/spi-atmel.c +++ b/drivers/spi/spi-atmel.c @@ -224,7 +224,7 @@ struct atmel_spi { struct platform_device *pdev; struct spi_transfer *current_transfer; - unsigned long current_remaining_bytes; + int current_remaining_bytes; int done_status; struct completion xfer_completion; @@ -1110,6 +1110,8 @@ static int atmel_spi_one_transfer(struct spi_master *master, atmel_spi_next_xfer_pio(master, xfer); } else { as->current_remaining_bytes -= len; + if (as->current_remaining_bytes < 0) + as->current_remaining_bytes = 0; } } else { atmel_spi_next_xfer_pio(master, xfer);