Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp712825imm; Wed, 1 Aug 2018 04:10:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfBhENd85Zzaa5LxNI0AIC3ENta5t7eLor4tkx1e0URXNCpyJDIemabITXaPmGhVPo6COv2 X-Received: by 2002:a62:c98e:: with SMTP id l14-v6mr26215773pfk.10.1533121846398; Wed, 01 Aug 2018 04:10:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533121846; cv=none; d=google.com; s=arc-20160816; b=y0kWy8zeT/rllYU6mW0AGSrN94UmXY6PvXRf0aCY4GzSB7oQ3/rQMOCeqF48FfOMIU kUukL+ThWywhCkp0EPtkMLeZmZ1vVeupHQZYG0ZGuFpcmBN68BBKlff458DLd117XyaU Sph/pr+gNEQduIWapxWEe+51/TmSogmbLl1+xZRupL3buY/fsn9d7qkYsp/vgjEOY/HQ UjllfRFbQU0cSC0E5RNuHUhNMMLsiAnmSFDLJRcqxRCbPOkPpYZouQ4rb8C7fLnKVro3 9dYZTdeAm+OBFqWBVeAbM3eXjgXHHQhie1Jf2SN/N6DkkWUbrGQ0Ltp8YqEuVu0LfeUz ovcw== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=Hfmmf9hixeUbkS6fJjZ//bXR8pIOecDQl+9DwYLRUSs=; b=PFDhwk0H4czxRD0uNZoQ94P6rfivFgD3xPaTh9uG5QWTmk3fGzf+zFay/ntZShbnke 0TlnTxUNZzDq4WdvunZEGoRJQT7fSzJ8F7DwHSA4r0+6Ba3O0CLzaT8J5p4SIKN3LZri v3APaWTha6L0VBPPZxNyOLVMUVbfF5tjs+nrD5FpPLDrgwdrtcb33ZclfbNUf3a3Khnd pdb7eD3nqJtUY+zNW2P8i21wT9jaJ6RzXDfWS9FH30e0RVtABrIqAP2ryEKWMc/tOegI z7/PpQvElU4CaIkxJ1wyaW/Ox1azOKjDEWLuvac3XtCP0BPYm2EiKRXhlZ6TNNfhCIiO Ng4g== 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 p19-v6si16569167pgm.109.2018.08.01.04.10.29; Wed, 01 Aug 2018 04:10:46 -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 S2388634AbeHAMym (ORCPT + 99 others); Wed, 1 Aug 2018 08:54:42 -0400 Received: from 5.mo1.mail-out.ovh.net ([178.33.45.107]:36809 "EHLO 5.mo1.mail-out.ovh.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730915AbeHAMym (ORCPT ); Wed, 1 Aug 2018 08:54:42 -0400 Received: from player798.ha.ovh.net (unknown [10.109.160.226]) by mo1.mail-out.ovh.net (Postfix) with ESMTP id 7ABB3117474 for ; Wed, 1 Aug 2018 12:52:28 +0200 (CEST) Received: from bahia.lan (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player798.ha.ovh.net (Postfix) with ESMTPSA id CDD835400C5; Wed, 1 Aug 2018 12:52:23 +0200 (CEST) Date: Wed, 1 Aug 2018 12:52:22 +0200 From: Greg Kurz To: piaojun Cc: Dominique Martinet , "akpm@linux-foundation.org" , "Linux Kernel Mailing List" , Subject: Re: [PATCH] net/9p/trans_virtio.c: add a terminal char for mount tag Message-ID: <20180801125222.3ba39416@bahia.lan> In-Reply-To: <5B616E3B.4050205@huawei.com> References: <5B6164F6.60004@huawei.com> <20180801081157.GA20127@nautica> <5B616E3B.4050205@huawei.com> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Ovh-Tracer-Id: 10442721637903210982 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtiedrledvgdefvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 1 Aug 2018 16:24:27 +0800 piaojun wrote: > Hi Dominique, > > On 2018/8/1 16:11, Dominique Martinet wrote: > > piaojun wrote on Wed, Aug 01, 2018: > >> chan->tag has no terminal char at last which will result in printing messy > >> code when debugging code. So we should add '\0' for tag. > > > > 9p is full of non null-terminated string so I'm not sure how I feel > > about it, is there anything wrong with how this is used or was this just > > when you tried to printf it? > The mount tag isn't a 9P thingy actually. It is provided by the server in the device config space, and it is never used in any 9P message. It could have been a nul terminated string from the beginning. Not sure why people opted to store it that way. > There is nothing wrong at the places using tag, as they calculated the > tag_len carefully. Adding '\0' for it will make the code more robust. And > I'm glad to hear others' opinions. > So this patch basically turns chan->tag into a nul terminated string, which is indeed more convenient and robust. Maybe you can update the rest of the code accordingly and drop chan->tag_len then ? > Thanks, > Jun > > > > > If it's just for debugging I'd suggest using the printf format "%.*s" > > with "chan->tag_len, chan->tag" arguments, FWIW, 9P strings received from the client are also converted to nul terminated strings: static int p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, va_list ap) { [...] case 's':{ [...] *sptr = kmalloc(len + 1, GFP_NOFS); [...] (*sptr)[len] = 0; } Cheers, -- Greg > > > > > > That said it's not like this is costly, so I'll take it if someone else > > thinks this is helpful > > > >> > >> Signed-off-by: Jun Piao > >> --- > >> net/9p/trans_virtio.c | 2 +- > >> 1 file changed, 1 insertion(+), 1 deletion(-) > >> > >> diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c > >> index d422bfc..49d71d6 100644 > >> --- a/net/9p/trans_virtio.c > >> +++ b/net/9p/trans_virtio.c > >> @@ -585,7 +585,7 @@ static int p9_virtio_probe(struct virtio_device *vdev) > >> err = -EINVAL; > >> goto out_free_vq; > >> } > >> - tag = kmalloc(tag_len, GFP_KERNEL); > >> + tag = kzalloc(tag_len + 1, GFP_KERNEL); > >> if (!tag) { > >> err = -ENOMEM; > >> goto out_free_vq; > >> --