Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1113566pxb; Fri, 27 Aug 2021 01:16:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWm2ySSxf2yu0H30/ctCvJbn3UkAd9o6rK219i2qmKm4oUFQwUmXyhXbtPPOI2vmzvlxOv X-Received: by 2002:a17:906:6009:: with SMTP id o9mr8817224ejj.266.1630052189049; Fri, 27 Aug 2021 01:16:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630052189; cv=none; d=google.com; s=arc-20160816; b=f3FUjQEAWHP9KIj3mo2aBJRUtAddeI4J+9Vjz4L5zw1LU1GN1OLJxjIwELWYFM6Y0A X8MggYWmiYQgDYngyBqZYDSlMqPzAbiyR4jclo+geHccHCl5LwyVTVNISjc2uW51fB6v 3kBF6kRgeUD0KUzrV7Oeb8J9wdR2owPjtP6i7sKQRFtQ97L0Sisp1iDIJbnsLJrx1xAQ o6j1+V+FQoLMt2Zxc4VFvzJhR8vwq9A9ufmp0Uv+9SYdFoGJ6hrdmaUfWklXTbNYa67i o4+ULqB8ELe8DrYAmz81ia0ViyIoaMWke4Ve0GB+LUZf77wtFmPNwESmolJa5Fvf0nlh Ttzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=bToKOUJenINwIiBTZGq+AWbH3Vj1HQvbe1YLg7+WRfk=; b=ME6BKQWBkkKYhtjqtT6FyDomGgsGztdR1TzeEWJwnfoKh9ApB7lQCbRZI11HQyymPU qZhMz8Tu1hJ3GTLETgY4TjFgf1rJTApVXhnpzZYAHvOH7wJ6fq+sQ8uhAr3SwVGPGgo4 SqUvchOIWxe44HEirwJBk3YpP59BqEE3fTJvx3POuBqr+J6nVqA32wIT8t5ERITLW8BR 8cp9XaC2P2rqPfyaWN6FdnLUE1klikZ0zO5IvAFbxWut3C0+wQyBtJABO/Xiu8DYDUb2 DMiYtHYDuibzostQXogzPrW+ixaKUx46W1nOlejw2AhOQPtGBbuRUG3Re5LpIo3LMcPA KS7A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r6si5865722edd.12.2021.08.27.01.16.06; Fri, 27 Aug 2021 01:16:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244494AbhH0IPC convert rfc822-to-8bit (ORCPT + 99 others); Fri, 27 Aug 2021 04:15:02 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.85.151]:38510 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244482AbhH0IPC (ORCPT ); Fri, 27 Aug 2021 04:15:02 -0400 Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-110-mwGT8myTNcm83mBe4IfVKA-1; Fri, 27 Aug 2021 09:14:10 +0100 X-MC-Unique: mwGT8myTNcm83mBe4IfVKA-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Fri, 27 Aug 2021 09:14:09 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.023; Fri, 27 Aug 2021 09:14:08 +0100 From: David Laight To: 'Dan Carpenter' CC: 'Pavel Skripkin' , "Larry.Finger@lwfinger.net" , "phil@philpotter.co.uk" , "gregkh@linuxfoundation.org" , "straube.linux@gmail.com" , "fmdefrancesco@gmail.com" , "linux-staging@lists.linux.dev" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH v3 3/6] staging: r8188eu: add error handling of rtw_read8 Thread-Topic: [PATCH v3 3/6] staging: r8188eu: add error handling of rtw_read8 Thread-Index: AQHXmLmGl/+E/B1vJUGWAidfG7snbKuFdLBA///xloCAAC/eAIAAAKqAgAFtSnA= Date: Fri, 27 Aug 2021 08:14:08 +0000 Message-ID: References: <20210826112745.5e1421ed@gmail.com> <20210826112127.GZ1931@kadam> In-Reply-To: <20210826112127.GZ1931@kadam> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter > Sent: 26 August 2021 12:21 ... > > > > ... > > > > > + len += snprintf(page + len, count - len, > > > > > "rtw_read8(0x%x)=0x%x\n", > > > > > + proc_get_read_addr, (u8) tmp); > > > > > > > > That is broken. > > > > > > > > > > Don't get it, sorry. Previous code did exactly the same thing, but > > > didn't check if read() was successful. > > > > Look up the return value of snprintf(). > > > > It's hard to understand what you are saying. I think you are confusing > libc snprintf with the kernel snprintf? In libc the snprintf function > can return negatives but in the kernel it cannot. This is not going > to change. Any code which checks for negative snprintf returns in the > kernel is wrong and should be fixed. > > Anyway, the code works fine. snprintf here is going to return a number > between 18-32 range. It's not going to overflow the PAGE_SIZE buffer. IIRC it is also in a loop ... Maybe, but the idiom is just broken. Largely the result of snprintf() is never the value you are looking for and should be ignored. Userspace fprintf() is even worse. If you care about the write failing you need to call fflush() and then ferror() (typically before fclose()). Fortunately I've never seen a 'must check' attribute on it. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)