Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp930960ybp; Wed, 9 Oct 2019 06:29:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqzK1zM9F+RaihFBEdNlb/gDImBoiqh8S/j4K35pjhEdNM9zs6JYzrPXXIO95eP2A8EpexkS X-Received: by 2002:aa7:c257:: with SMTP id y23mr2994828edo.39.1570627753601; Wed, 09 Oct 2019 06:29:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570627753; cv=none; d=google.com; s=arc-20160816; b=bHHYyoDalwE5Cy89jq3msXSrePogPdZNXElWZv83oda9h614AWeIT2uHiAMbiWlxU3 /M5q3vKlUv9wSSbh4vioIDtSzbEOPF5C9G9pXCBnaeTIPX0AKaiF8+m0AyPPmlP6RhN+ jAUhvxPgRFLVFxTnTWXyjIJAJWRTZk4buGpxRVfNM2uZt5Gm92bj84wBTLv4i3iA9DQZ /ixYzrE84g8Jo5d/TUaUqQork47lZmKg2gzTgptFQJSSV3B4YUXgEtZtE+rsNPt7zCl9 kPpuiOR+u1xDeRpzC4W93jxGNatw6SggAHgoP3XYsPPoShbwNUjsdcQ6ouIxN6peg1S/ GTCA== 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=WJWP5QMUkAgHs6BnCYZNp8h84d1YBL5Bm1yud/rHHZg=; b=pPsRNFWlXoCsAZgrbKhThNsLcR5rCWbMYz0Beaeso999vmuulBXNB8Jny+ElZ9Nqic Y4DjiJE67w+ODLKPEC3pg6hbo7uHZnhFyAh9fRQrCd0fTucQYONlm159LzyAqBIPYwLg Glc2XEoKMUTDe8mVyitO4hRpDPO6SiXtmTXNYhw9/fVfwkTQ2NW9Y7HdBrOi91vkcaj9 BbR7zUhNCQNMkDSm8hIOS65xZSB1kLE+5PPD/bHMK3XA8k2Zr6y2CfOYaYoFHftO6E3C udsoXwquJgS2KxNF/ZepmJJ10EpE+lTiMgmVLklqPmhFMKocgvWIAN8Kbvrqv5iHhy6p cGgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=Jm+mF2rD; 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 l15si1152549ejz.74.2019.10.09.06.28.48; Wed, 09 Oct 2019 06:29:13 -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=Jm+mF2rD; 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 S1731345AbfJIN0Y (ORCPT + 99 others); Wed, 9 Oct 2019 09:26:24 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:38016 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731260AbfJIN0X (ORCPT ); Wed, 9 Oct 2019 09:26:23 -0400 Received: by mail-lj1-f196.google.com with SMTP id b20so2493888ljj.5 for ; Wed, 09 Oct 2019 06:26:21 -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=WJWP5QMUkAgHs6BnCYZNp8h84d1YBL5Bm1yud/rHHZg=; b=Jm+mF2rDsCJLcrUlB0SLiwko2Z9Ves98s22gSAsrBVZEVcVXfdwdOX7ZJbB2fF3d2T vKttvPExXAug4yqPWc4vwbzwUhsxX/Uy7mwYXY4KALSDq+YjoBb0exsJD8/Ho6kGT+bE dqiCaslb16ZKB+zIWqGcpDxrd2wnBcHzk+Hzg= 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=WJWP5QMUkAgHs6BnCYZNp8h84d1YBL5Bm1yud/rHHZg=; b=kjd75pw8dSas70V7mdgo00qotsGalBoNwHWaja4sZw+5okTQPepmI7zEYRsoWuFMxC DKR9YYjj5b9l7+YsN6m7dfElfsbMhdfqh6C3ziEHr8nIDihwZZgRkL0faRFOcpueBNKU vpBvgvhghxVcSXPB36+8Sm5FAoG9BSZi4NdMlmGzLzrouBcZf1tStypRc5T1P/6OnjVk uPkWI5aE6+0w7IIxTnKBccZSKXlvqO9YOmGwUBI+FBnKVsgwzZ/jetOx+CwUHXzVsB0b phuEkpB/4elAlmj1pBOjK3SUpgiGiUiF6To2o/9F9dRl1nWT0HBZmr5sfF70YDT4+HJz 94UA== X-Gm-Message-State: APjAAAURkVp1/Y2LXowtYEG/oI7Pq5E91zABp9o9wgWOgkA6hbpSXLsw DyY0+6OJVlFoQdKTxkj3FqPEcDQonPUy7Y+f X-Received: by 2002:a2e:2943:: with SMTP id u64mr2382988lje.241.1570627580325; Wed, 09 Oct 2019 06:26:20 -0700 (PDT) Received: from [172.16.11.28] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id r19sm472597ljd.95.2019.10.09.06.26.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Oct 2019 06:26:19 -0700 (PDT) Subject: Re: [PATCH] string.h: Mark 34 functions with __must_check To: Markus Elfring , kernel-janitors@vger.kernel.org, Alexander Shishkin , Andrew Morton , Andy Shevchenko , Joe Perches , Kees Cook , Nick Desaulniers , Steven Rostedt Cc: LKML References: <75f70e5e-9ece-d6d1-a2c5-2f3ad79b9ccb@web.de> From: Rasmus Villemoes Message-ID: <954c5d70-742f-7b0e-57ad-ea967e93be89@rasmusvillemoes.dk> Date: Wed, 9 Oct 2019 15:26:18 +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: <75f70e5e-9ece-d6d1-a2c5-2f3ad79b9ccb@web.de> 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 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. You're also not consistent - strlen() is not annotated. 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); ^~~~~~~~~ [1] Just might. The problem is the __must_check does not mean that the return value must be followed by a comparison to NULL and bailing out (that can't really be checked), it simply ensures the return value is assigned somewhere or used in an if(). So foo->bar = kstrdup() not followed by a check of foo->bar won't warn. So one would essentially only catch instant-leaks. __must_check is much better suited for functions that mutate a passed-in or global object, e.g. start_engine(engine). Rasmus