Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp934422pxj; Fri, 21 May 2021 02:34:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUU2Gw9Byd1K6N/ELILK9XXUvNz8aKCGX7g1c7YhWFhsc7o6Z3sR221I8sUllelg2GYoOZ X-Received: by 2002:aa7:c6cd:: with SMTP id b13mr10110331eds.94.1621589696186; Fri, 21 May 2021 02:34:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621589696; cv=none; d=google.com; s=arc-20160816; b=EuroGXuNhkJwm8W4naGIuI5r7iiy3bUJcZT8tWYXyLeY6JflJOJLGZmXWq20itLM9F 7OtesmbUw0+JJT7+lf5q7k0nMzsIBhHUE7MzYEC9qzJM9icVU9DDVfpXubYX6dpxIOle O5MIdDIn4vqli9kNOXk8qdu0+5+d7QJRt3gaEdWC+NTvAWSAvE0N1Aa+48/XPG0jVhsi HqjDRnpn8SCLC4m46Fo9BUrNOsYW2KJZ8spGjLS1MLrFAeOGy0xogdctplP4b6YJOcJj HwEAAytKGhWE1uxwthjeZN72ie7iGOGkJoB/+us0cyR8PzYuA+fiRvf1SMG7V7exlmUK +ULw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:references:in-reply-to:subject :cc:to:from:mime-version:content-transfer-encoding; bh=vPpKGr/QM55h9PoAqoy3AhyvFXx9WBcpU9wACHUOZak=; b=anl2H+sYjGm3f05HG8ALplcr9X2TtjAtZRavJBzUZx2LSI0uW5kDOVBv0i63G7b2sI zR6mXuWeUAIru/K363ElW/33wAs8khz/ztj2KokVJGdTl/njv5zkeV3BE7pF3OtWB55J Q9NLYNMxeMrbvWzRIjU/rxTuvVMOm0cK3YWYhrrNQTasHmnuyN+2jCNIZ55RFpikFaCj t43zZwxI5bRBj7sJkDP5IzYPZcaGaghPMKRJu09L/R8V6dfFwwU9SJ8UyaG1cT0w5bem 8c7zvJNDlS4xpuW4b70yfyaFrAdK6X/I89TI0ZvYtsByU+Nb9GqHWha8qXNTaZt94UbF Rw5Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u8si5082555edd.67.2021.05.21.02.34.33; Fri, 21 May 2021 02:34:56 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238893AbhEUD3q convert rfc822-to-8bit (ORCPT + 99 others); Thu, 20 May 2021 23:29:46 -0400 Received: from mx2.suse.de ([195.135.220.15]:59240 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236848AbhEUD3q (ORCPT ); Thu, 20 May 2021 23:29:46 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 539FFAB64; Fri, 21 May 2021 03:28:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 From: "NeilBrown" To: "Austin Kim" Cc: gregkh@linuxfoundation.org, tj@kernel.org, linux-kernel@vger.kernel.org, austin.kim@lge.com, austindh.kim@gmail.com Subject: Re: [PATCH] kernfs: move return value check after kmalloc() In-reply-to: <20210521025525.GA1379@raspberrypi> References: <20210521025525.GA1379@raspberrypi> Date: Fri, 21 May 2021 13:28:17 +1000 Message-id: <162156769760.19062.15467223033723371296@noble.neil.brown.name> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 21 May 2021, Austin Kim wrote: > With 414985ae23c0 ("sysfs, kernfs: move file core code to fs/kernfs/file.c"), > 'return -ENOMEM' is executed when kmalloc() returns NULL. > > Since 'commit 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc > files use the buffer.")', 'return -ENOMEM' statement is not properly located. > > Fix it by moving 'return -ENOMEM' after return from kmalloc(). I don't think there is anything to "fix" here. The current code is correct. The difference between the current code and your new code is purely a difference in style. I don't object to your change, but only if it is presented as a style improvement. It is not a code fix. NeilBrown > > Fixes: 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.") > Signed-off-by: Austin Kim > --- > fs/kernfs/file.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c > index c75719312147..c5e2429af836 100644 > --- a/fs/kernfs/file.c > +++ b/fs/kernfs/file.c > @@ -191,10 +191,11 @@ static ssize_t kernfs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) > buf = of->prealloc_buf; > if (buf) > mutex_lock(&of->prealloc_mutex); > - else > + else { > buf = kmalloc(len, GFP_KERNEL); > - if (!buf) > - return -ENOMEM; > + if (!buf) > + return -ENOMEM; > + } > > /* > * @of->mutex nests outside active ref and is used both to ensure that > -- > 2.20.1 > >