Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp936784imm; Wed, 1 Aug 2018 07:40:54 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeKdmQiCAkLX0N3WCPnODofNFA7vR9Asllq+40WqRqLC4+jJqjTfWYA15BbIMpP4uu0vg5I X-Received: by 2002:a17:902:708b:: with SMTP id z11-v6mr24514570plk.262.1533134454484; Wed, 01 Aug 2018 07:40:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533134454; cv=none; d=google.com; s=arc-20160816; b=OKRKFCsBy98DRymCtERGPWcHyUoEY/R1/WeAX+7/TFDtjJWvTBFmHu92+4wSlXdsXT pAVvE+gpl1+psozq8ytL0rAlTqdfbNiPqST2D0ywOE97rmeT0klgE3q0A48W83oGTSAW RcKI33drrvoFUuYOc53iEPlvlwf4qPUOHw063CfKGeN0/EQomHUvX/PGbutpaf6fQftQ pPVLkL5uNdNhIUFMhafJkBxadOBBOneYuS9q8cQ6py52U3ENQi/uwm7aCG0O6LvCNZCq 3M7ypzB2wgRNdi9vK8O1vruEybweKZ0C4Y1T/cI/jJ2Wk5qAlPoqAEDyKFek0wNaJ13X 76ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=ZVtVNCuJ0hZ640GnlzQAmgt7QLhmvMT7twHo4Dgg/wM=; b=yUjbT9RsJ6KDB7PBQ3zjrJkzZ7IUIKmi1d/4jZxnA9hiOGoZr995ZdeuRiktAypgYV VHDgJh1JPoHrIODyvgUMDhDQ5TkXc1FUuJjo5x7TUYshd2CntR2VJEKffS996R3rKs5i QDcM4zd98O7TvpUGd68U2Lpj/Lt/P9UWAyBfwmEw8HIL2yxbeG7w/8HY/GuM9n5FNPVI i/K6w8HNnH1PJ5j2mKQYU1/6ubFo1U4FgkmifRSTxA96E/BTYwmoI6DRSDhqRke++8v9 p5fhNdF6mM2Cp/D8t4V7VvrwUudTnTFM18twgvVP0qFKryu0Z+gYcfUgxo18c4L7+cru DkaQ== ARC-Authentication-Results: i=1; mx.google.com; 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 x65-v6si17613034pff.196.2018.08.01.07.40.39; Wed, 01 Aug 2018 07:40:54 -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; 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 S2389639AbeHAQY6 (ORCPT + 99 others); Wed, 1 Aug 2018 12:24:58 -0400 Received: from nautica.notk.org ([91.121.71.147]:40467 "EHLO nautica.notk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389570AbeHAQY6 (ORCPT ); Wed, 1 Aug 2018 12:24:58 -0400 Received: by nautica.notk.org (Postfix, from userid 1001) id 2EBF9C009; Wed, 1 Aug 2018 16:38:55 +0200 (CEST) Date: Wed, 1 Aug 2018 16:38:40 +0200 From: Dominique Martinet To: Greg Kurz Cc: v9fs-developer@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, Matthew Wilcox , linux-kernel@vger.kernel.org Subject: Re: [V9fs-developer] [PATCH 1/2] net/9p: embed fcall in req to round down buffer allocs Message-ID: <20180801143840.GA21463@nautica> References: <20180730093101.GA7894@nautica> <1532943263-24378-1-git-send-email-asmadeus@codewreck.org> <20180801161413.0523a821@bahia.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180801161413.0523a821@bahia.lan> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Greg Kurz wrote on Wed, Aug 01, 2018: > > @@ -263,13 +261,13 @@ p9_tag_alloc(struct p9_client *c, int8_t type, unsigned int max_size) > > if (!req) > > return NULL; > > > > - req->tc = p9_fcall_alloc(alloc_msize); > > - req->rc = p9_fcall_alloc(alloc_msize); > > - if (!req->tc || !req->rc) > > + if (p9_fcall_alloc(&req->tc, alloc_msize)) > > + goto free; > > + if (p9_fcall_alloc(&req->rc, alloc_msize)) > > goto free; > > Hmm... if the first allocation fails, we will kfree() req->rc.sdata. > > Are we sure we won't have a stale pointer or uninitialized data in > there ? Yeah, Jun pointed that out and I have a v2 that only frees as needed with an extra goto (I sent an incremental diff in my reply to his comment here[1]) [1] https://lkml.kernel.org/r/20180731011256.GA30388@nautica > And even if we don't with the current code base, this is fragile and > could be easily broken. > > I think you should drop this hunk and rather rename p9_fcall_alloc() to > p9_fcall_alloc_sdata() instead, since this is what the function is > actually doing with this patch applied. Hmm. I agree the naming isn't accurate, but even if we rename it we'll need to pass a pointer to fcall as argument as it inits its capacity. p9_fcall_init(fc, msize) might be simpler? (I'm not sure I follow what you mean by 'drop this hunk', to be honest, did you want a single function call to init both maybe?) -- Dominique