Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751571AbbEGPLW (ORCPT ); Thu, 7 May 2015 11:11:22 -0400 Received: from mail-am1on0100.outbound.protection.outlook.com ([157.56.112.100]:20000 "EHLO emea01-am1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751040AbbEGPLR (ORCPT ); Thu, 7 May 2015 11:11:17 -0400 Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; Message-ID: <554B807F.60902@ezchip.com> Date: Thu, 7 May 2015 11:10:55 -0400 From: Chris Metcalf User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Dan Carpenter , Geert Uytterhoeven CC: Linus Torvalds , Al Viro , Fabian Frederick , Randy Dunlap , Rickard Strandqvist , Greg KH , Peter Zijlstra , "David S. Miller" , Frederic Weisbecker , Andrew Morton , Sam Ravnborg , Stephen Rothwell , "Theodore Ts'o" , Grant Likely , Linux Kernel Mailing List , Linux-Arch Subject: Re: [PATCH 2/3] string: provide strscpy() and strscpy_truncate() References: <1430409677-13284-1-git-send-email-cmetcalf@ezchip.com> <1430409677-13284-3-git-send-email-cmetcalf@ezchip.com> <20150506150140.GB12986@mwanda> <554A3161.3030609@ezchip.com> <20150506155951.GS16501@mwanda> <20150507090034.GV16501@mwanda> In-Reply-To: <20150507090034.GV16501@mwanda> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [12.216.194.146] X-ClientProxiedBy: CO2PR11CA0031.namprd11.prod.outlook.com (10.141.242.169) To HE1PR02MB0780.eurprd02.prod.outlook.com (25.161.118.144) X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HE1PR02MB0780; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:HE1PR02MB0780;BCL:0;PCL:0;RULEID:;SRVR:HE1PR02MB0780; X-Forefront-PRVS: 056929CBB8 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6049001)(6009001)(51704005)(377454003)(479174004)(24454002)(47776003)(5001770100001)(4001350100001)(76176999)(66066001)(54356999)(65806001)(87976001)(23746002)(19580395003)(19580405001)(33656002)(83506001)(5001960100002)(93886004)(86362001)(92566002)(46102003)(36756003)(15975445007)(122386002)(77096005)(62966003)(77156002)(42186005)(2950100001)(50986999)(189998001)(50466002)(40100003)(18886065003);DIR:OUT;SFP:1101;SCL:1;SRVR:HE1PR02MB0780;H:[10.7.0.41];FPR:;SPF:None;MLV:sfv;LANG:en; X-OriginatorOrg: ezchip.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2015 15:11:08.6808 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR02MB0780 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1664 Lines: 37 On 05/07/2015 05:00 AM, Dan Carpenter wrote: > On Wed, May 06, 2015 at 06:45:56PM +0200, Geert Uytterhoeven wrote: >> On Wed, May 6, 2015 at 5:59 PM, Dan Carpenter wrote: >>> We actually do have a __must_check tag so it's easy enough to force >>> people to check. A different option is we could make it trigger a >> People tend to ignore compiler warnings... > We're doing a lot better these days with zero day build testing. There > is not even one ignored __must_check return in my allmodconfig. If we keep the strscpy/strscpy_truncate distinction, I agree that having __must_check on strscpy seems like a good idea. >>> WARN_ONCE(). >>> >>> #define strXcpy(dest, src, len) (({ \ >>> ssize_t __ret = strscpy_truncate(dest, src, len); \ >>> WARN_ONCE(__ret < 0, "strXcpy trancates\n"); \ >>> __ret; })) >> Which will probably trigger only in extreme cases in the wild, not during >> development. > It's less subtle than just putting an empty string there so we're more > likely to get bug reports than with the original code. The problem with WARN_ONCE() here is that we may be using strscpy() to take user input of some kind. If so, we don't want to warn if we are truncating the string - we just want to return a suitable error up the call stack. -- Chris Metcalf, EZChip Semiconductor http://www.ezchip.com -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/