Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1427260pxu; Sat, 5 Dec 2020 16:24:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJw7mNHoI97AST5HWPWuUaexKk4PWZZr8kQH60Qj9RKF31jexya7ewQ1FI+ZiyLZ30FkvByG X-Received: by 2002:a17:906:770d:: with SMTP id q13mr12832725ejm.409.1607214295690; Sat, 05 Dec 2020 16:24:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607214295; cv=none; d=google.com; s=arc-20160816; b=Ftj8XD+OTjxBXWgQI7/h2GDCZYS9oMC3/3JIF+UI3/WhDm33mStwP2aRZVB8508tDp mo1/1jot/NFr46L3lPQMPC/8AwKikjo9Ye8r6jqwNLDAwDODY1NYRp4Osre/61kLpjPV PHICxhh8g/bDTNgjLhD8EpqULrnZnOY1CrWeoVRjQ6brRNrNHmmTyOm6Yldvixpbt0ZU CbNi1P0uTaahuTiD54geK7oqOAxic41LzjiEv8IftnmgIPpmheyb7W4G+xOF84+I+IOD 8nAVO0BJ9M3AiDUmbhcgjOYSv1+hJwwFQDrzX0Mf7e2JCcStdQi5I/AqNUIRcIYImvMs B4Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=3IgKPEXPEhoiVhProzrF1Nh2SnPmElxALGug4CytgfI=; b=WAZIuf2njIL2noROUOAbI2nP7yFvjWGJaY+zz3U3F+38MY8GJ6OsZucCA608+hwVy1 AeO3AsjkYX+j3upFXIskVyNSviHDWzMvPo+NjE7HHAWcMX3AHd7Nvv8v94SV3RIzS4xv 7gbrzQVP0J6zLs7t10sZr4Rq/TORT+dVuiwWr6PSEpPkLDbxkdtW82cwDvvDCQoCrxYN 0ORIjNUJn9dq+CLRWJ8qNcr+Lh0AkjGCMEOioUPmu5k1FsgszfBmtFvhMyvf0/tFUdHY XVDj+faimcNxcMF2zMnFVfraSkHPzOjP80d7rkoDHtNP+pT9sRZwYN7jCzCtSs1dU0ex UOyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Gle+JDe8; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gj15si4197455ejb.597.2020.12.05.16.24.21; Sat, 05 Dec 2020 16:24:55 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Gle+JDe8; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726057AbgLFAOi (ORCPT + 99 others); Sat, 5 Dec 2020 19:14:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725966AbgLFAOh (ORCPT ); Sat, 5 Dec 2020 19:14:37 -0500 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BD15C0613D1; Sat, 5 Dec 2020 16:13:57 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id lt17so14210331ejb.3; Sat, 05 Dec 2020 16:13:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=3IgKPEXPEhoiVhProzrF1Nh2SnPmElxALGug4CytgfI=; b=Gle+JDe8dq1mS9tatLrCtwEHambE00p2187JymYCoH3f4Ao7io13hqwYvA2oCxuA30 XN+Kv/br6c3CHYzBS2xX7UKSwHQR72yGJCvMXQ6L9VR9to9CXUhvPkezsEzuOvRtYc1I 6Qn6EKFgSNKrrv+9eIoFMFdIwkwdNRlb8YwhYsICb79J8D+C6P4426y2xlola7XpXYCn wxgax4SvOaLyX/VhESfmoI781HXHWwfzabJgCd6TB5/PW8gA57FnJf2d6Eg88ewZ68ye L50i5Wue1Nwy+fJ+psrEc4YKRKlJxqXmWZBxHLMX06Os9FMIevT4Q6KnsgTdg8tRmP/r wRkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=3IgKPEXPEhoiVhProzrF1Nh2SnPmElxALGug4CytgfI=; b=oL3EaXq3F1Viz5OMdDeUbd/nMs5anq0gBgLVXJPzg4wgf0af5nPkgMLPfuXSnHz30G YZQR/Jp+JzttBr6OyK7Q15p31M4THjkYiRuuzCXMYK0bd1Ut9MCBHKFx1SxCgJKTMtLW zyUzgHFMXRYHDXenvbGSeAeHyTKhO0o/s4wKqizmD2an5sdWX8XQgZ5Y7UJoItfNw1JD RmdDCSKUVirB+Z0Ylnpe+exrMYgb9PBj7im2TBZy7ufjMZI9M1z+CTy3sWF4X7qZorXb W3pKBD0W+TWLkrgpC0p3DqI2ahxewe+kHXYSF+WMsWf9PI8zmLe3JzM235z7WBISwLu8 mGcA== X-Gm-Message-State: AOAM53302snKS2/CLtme+FTHcvr65UQxFSKaVtkUVSLF90zqJs4EnTx2 rSqA5KRAaCD5X1gp2tNGWRg= X-Received: by 2002:a17:906:4050:: with SMTP id y16mr12774577ejj.537.1607213635882; Sat, 05 Dec 2020 16:13:55 -0800 (PST) Received: from ltop.local ([2a02:a03f:b7fe:f700:78c1:dc3d:b5fd:9b12]) by smtp.gmail.com with ESMTPSA id gl2sm6390263ejb.29.2020.12.05.16.13.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2020 16:13:54 -0800 (PST) Date: Sun, 6 Dec 2020 01:13:53 +0100 From: Luc Van Oostenryck To: Linus Torvalds Cc: Jakub Kicinski , Sparse Mailing-list , Linux Kernel Mailing List , edwin.peer@broadcom.com, Zhang Changzhong Subject: Re: sparse annotation for error types? Message-ID: <20201206001353.fhfu6wzn7nfg7fmv@ltop.local> References: <20201205143250.2378b9f9@kicinski-fedora-pc1c0hjn.DHCP.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Dec 05, 2020 at 03:10:15PM -0800, Linus Torvalds wrote: > On Sat, Dec 5, 2020 at 2:34 PM Jakub Kicinski wrote: > > > > Am I the only one who thinks this would be a good idea? > > err = third_step(obj, 0); > > err_undo_2s: > second_undo(obj); > err_undo_1s: > first_undo(obj); > return err; > > iow, the "undo" parts are often done even for the success cases. This > is particularly true when those first steps are locking-related, and > the code always wants to unlock. > > Sparse also doesn't really do any value analysis, so I suspect it > wouldn't be trivial to implement in sparse anyway. Yes but ... (see here under). > Having some kind of smarter compile-time assert could be useful in > general, but as mentioned, sparse doesn't really do value range > propagation right now, so.. > > Luc, any reactions? I agree but the code Jakub showed is very constrained: * only 2 return points * one of them being 0, the other is to be checked. and I think this should be checkable easily, something like: * identify the highest point that can't reach the 'return 0' * check that the only way to reach this point is via a zero/non-zero test of the 'err' variable/returned value (which is a very limited kind of value analysis after all). But sure, these are rather strict constraints but maybe it's common for net drivers? Otherwise, yes, it's probably better to annotate the function itself or the point of interest (via some kind of assertion) than the variable. I've not much idea how much this would be useful, though. -- Luc