Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp992647ybp; Wed, 9 Oct 2019 07:22:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqzVKx/lCKj93/MtD6LmrY1m3kRcf/sNA9R/3LheoabY1u+iIhePd8y+XcoyIReyvDojIIoI X-Received: by 2002:a17:906:fcd4:: with SMTP id qx20mr3119576ejb.257.1570630926641; Wed, 09 Oct 2019 07:22:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570630926; cv=none; d=google.com; s=arc-20160816; b=CsaKfS4pXjrsz7QSE1ULH2KITNwdUt8ldrpT2Paij2if1/ebV1PmO3hEXnpdu2vQ/v bGGuHzfrDEn66Q9YCkm2AT5+MDau+O4IX0rFSeDbPqqornXcJWxgJz+Zve+23UgNQ/+R d1Il9pqxp0XK8wMR4RNrEJ4MHlhrtF2LOYAk1dEuk9Hl2LEuAKNriN4jDDXB8KZONPE0 fl/vgRptbhVkw57O1FEjZCaFOR7lQS5Dn7b2v0nn/niF5C6nU9eBpJZx3nQR0MPNgZgw UwdYYoOulGdCgKnAe/WuB3r9tXwd3QOOHi4F8s8t+grxgLGD/k1lzqKEFk4DHHJxNzIU kIlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=qjoBWNah/ifg5o3F6/ggCjuw7oqH/AZ2UOt9h6CGFbo=; b=RBmppvHq6LevrrhcSkLLHcAkGN3bCoHYPrHn2dvK7HhmzkjpzfwF3+5CII9N4h5qo7 enBYwvB4UxxmM6Wxs+FS+ZNZ05cTrFQjF1XWItxuDH+LESZVPObeYpSDblRZpmV4dJ3G tcnDywFI7EMZwi1UYnlYxvmU4pRmD1goEzaNPMst1/N9HsiPbQ9ySZfF+GJn3fghAFqq VFBRkgQDAhn9uhP1RQz4NXEPv/cjpY2z6PXE6hiQMA2gc8RHoOIyt9zuKnsFu6nrHd/r x3WtKHZN7IfyzLKCRdk7ETPycUSKvrN+dn59rU8mIGDsZ41afxoBNphPgFPswP1yYdDy L8ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=I00cEMC2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q1si1105466edj.354.2019.10.09.07.21.42; Wed, 09 Oct 2019 07:22:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=I00cEMC2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731386AbfJIOVZ (ORCPT + 99 others); Wed, 9 Oct 2019 10:21:25 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:35426 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729491AbfJIOVZ (ORCPT ); Wed, 9 Oct 2019 10:21:25 -0400 Received: by mail-lf1-f66.google.com with SMTP id w6so1823974lfl.2 for ; Wed, 09 Oct 2019 07:21:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=qjoBWNah/ifg5o3F6/ggCjuw7oqH/AZ2UOt9h6CGFbo=; b=I00cEMC2A7RAbE1W1pCwIixhLBGWr52k0GxZdw/bzo/vHaGVtYJNzsa3mvqv9fMuuz LDOZ1HkZC0eA1/W04lDYWq1c+2t6zT+xn5qVWOR4JqcXgJlwlvqtqoud48LR2Ih7lfSV wPdILcXkMgC0QS+RWPjvT5aQ+tdQ6WSOiD+y8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qjoBWNah/ifg5o3F6/ggCjuw7oqH/AZ2UOt9h6CGFbo=; b=cKIBHEbh+Ij0xacuj1rI4TAjlbSaSAt9k2gFHg0tLOOVGpvRyv9bMrlKVPS18culbC t0rmGtqDK1dKyaF0F/fOmRu4JviQJ0aG+5jcLpvRWvFa3jSQyfmbJ83n+yuq0jbcIxCo qspTegw5Pf4N12yzuU00c4l+1Qyy0iJx90L3bs2aZRq4nPBdYjdYYnYZFZUeMD4KPfzS kirICcbQlMxcd9tiF+5OGG8sSKOdf+T9pgL9dusjojc9QDK0fXv6qdqdFjo/34otogLO bhOQLxivbEO7RXsnqOaeEtk4zWwN5DP1juiz74Ega0IsSrnP06HZAeozVNSO6Y6tybiQ b1Ng== X-Gm-Message-State: APjAAAUIeP9aSjkcfkGLm8UVvc/R21dbSqWgKjsSBB5xRELv30RPQqdh wtmURxxuvrNLAd2PXs/lbi1He4sHAP+Qi2U2 X-Received: by 2002:a19:ae05:: with SMTP id f5mr2216670lfc.165.1570630882856; Wed, 09 Oct 2019 07:21:22 -0700 (PDT) Received: from [172.16.11.28] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id z14sm500967lfh.30.2019.10.09.07.21.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Oct 2019 07:21:22 -0700 (PDT) Subject: Re: [PATCH] string.h: Mark 34 functions with __must_check To: Dan Carpenter , Rasmus Villemoes Cc: Markus Elfring , kernel-janitors@vger.kernel.org, Alexander Shishkin , Andrew Morton , Andy Shevchenko , Joe Perches , Kees Cook , Nick Desaulniers , Steven Rostedt , LKML References: <75f70e5e-9ece-d6d1-a2c5-2f3ad79b9ccb@web.de> <954c5d70-742f-7b0e-57ad-ea967e93be89@rasmusvillemoes.dk> <20191009135522.GA20194@kadam> From: Rasmus Villemoes Message-ID: Date: Wed, 9 Oct 2019 16:21:20 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20191009135522.GA20194@kadam> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/10/2019 15.56, Dan Carpenter wrote: > [ I haven't reviewed the original patch ] > > On Wed, Oct 09, 2019 at 03:26:18PM +0200, Rasmus Villemoes wrote: >> On 09/10/2019 14.14, Markus Elfring wrote: >>> From: Markus Elfring >>> Date: Wed, 9 Oct 2019 13:53:59 +0200 >>> >>> Several functions return values with which useful data processing >>> should be performed. These values must not be ignored then. >>> Thus use the annotation “__must_check” in the shown function declarations. >> >> This _might_ make sense for those that are basically kmalloc() wrappers >> in one way or another [1]. But what's the point of annotating pure >> functions such as strchr, strstr, memchr etc? Nobody is calling those >> for their side effects (they don't have any...), so obviously the return >> value is used. If somebody does a strcmp() without using the result, so >> what? OK, it's odd code that might be worth flagging, but I don't think >> that's the kind of thing one accidentally adds. > > > if (ret) { > -EINVAL; > } > > People do occasionally make mistakes like this. It can't hurt to > warn them as early as possible about nonsense code. In that case, ret (which I guess comes from one of these functions) is indeed used. And gcc should already complain about that "statement with no effect" for the -EINVAL; line. So I don't see how adding these annotations would change anything. >> And, for the >> standard C functions, -Wall already seems to warn about an unused >> call: >> >> #include >> int f(const char *s) >> { >> strlen(s); >> return 3; >> } >> $ gcc -Wall -o a.o -c a.c >> a.c: In function ‘f’: >> a.c:5:2: warning: statement with no effect [-Wunused-value] >> strlen(s); >> ^~~~~~~~~ > > That's because glibc strlen is annotated with __attribute_pure__ which > means it has no side effects. I know, except it has nothing to do with glibc headers. Just try the same thing in the kernel. gcc itself knows this about __builtin_strlen() etc. If anything, we could annotate some of our non-standard functions (say, memchr_inv) with __pure - then we'd both get the Wunused-value in the nonsense cases, and allow gcc to optimize or reorder the calls. Rasmus