Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp559005pxx; Thu, 29 Oct 2020 08:56:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvqmgt1sbTSGupIAquTlHUhJ2zyLZYJqRGutR+pornQ/aWmmUt7DIbJeQjpGb7AL3iw/Yl X-Received: by 2002:a17:906:319a:: with SMTP id 26mr4937206ejy.9.1603986998003; Thu, 29 Oct 2020 08:56:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603986997; cv=none; d=google.com; s=arc-20160816; b=HxRa5E3dfIWvh5fpj7/iQXZSRcgkte/S0VGtQjfujfU44NB9Th8q9CRJTqy8Q9fvli FIqR3fapyCYpH/7Y2XJtZT1DKnlLdTmiBf23MJm9+hjrVeYPOAFtZskATOrzw5uFbOYt GQGIvi4/fQCD+CTuvUmWwaitCJSCy5A0PH5L5KAA8XPzlt5bHG2JtzS1bk4pb/e/9NMn axof7fD2Gz/kw3WTo1GuQXvQe2j5bM25VxRxpC/B/wXsXGSEyMcQQ7eMzJEWgUObteJY 6odRCPexcZCK78tGlC75eBe77AXFExBH/OQ666hy31aoAOOKpaMiL1LCF6M6t8aReSer L6fQ== 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=c4K455W0ep1zflq5MHyazQVv2UbLiu6nKDQy+au0GSo=; b=kvzhW1qg8e/KsYsLLn/8Fr71/qO5htf4c1n8ylCiFF8ZSQBvuZcLfcRugGc+2QCrB6 NAlaXfHBqVl9RjHH5eX3lFbHD89WCJVZ9C6cdWOFPT2JW61XIuJGZrU/IgDtr0wqwxzR SeZvunrPXsvI0AxxvvSqsenlNwRG3rJAOPRGg1bVvEn5K1a1a9DfX+tTjc2nff9VK6E2 PUHdjDgQrBq4OYp+PXyS2no+6i9bu27M3uDc6t5vqBg6Y4v/avxLpaKnVy9SqIKSrf9w yX9FwzMdjUjyV9/1bWUmPVnV7NiaPyNOnzuKOA1h3FZoWlzIP27PwW4QJq8FA+5xqq6f nGHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UBHEU8f0; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x8si2310376edq.532.2020.10.29.08.56.13; Thu, 29 Oct 2020 08:56:37 -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; dkim=pass header.i=@kernel.org header.s=default header.b=UBHEU8f0; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728232AbgJ2Py4 (ORCPT + 99 others); Thu, 29 Oct 2020 11:54:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:57662 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727966AbgJ2Pyz (ORCPT ); Thu, 29 Oct 2020 11:54:55 -0400 Received: from sol.localdomain (172-10-235-113.lightspeed.sntcca.sbcglobal.net [172.10.235.113]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0A8C0206B2; Thu, 29 Oct 2020 15:54:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603986895; bh=87aI4/JSMDDksYiET/w/mskCfHBQKdtbdR1IFIz2HlE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=UBHEU8f0aEe2A/0HMk7c+LCoGolhLfFyok4S0WPt/8F4nJvewDoafydRcDs9V+Tbn 0G8iqUnYBYI9na/qMiiHNaV8IBESTZ1sVK3+tw8Q455FAx+c7PRi1qORc3/mHApK5X mRZDf2MVLaM6nVZkpr88N7YI+4sSDCs968KKURAY= Date: Thu, 29 Oct 2020 08:54:53 -0700 From: Eric Biggers To: Chao Yu Cc: Daeho Jeong , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com, Daeho Jeong Subject: Re: [f2fs-dev] [PATCH v5 2/2] f2fs: add F2FS_IOC_SET_COMPRESS_OPTION ioctl Message-ID: <20201029155453.GB849@sol.localdomain> References: <20201029041538.4165209-1-daeho43@gmail.com> <20201029041538.4165209-2-daeho43@gmail.com> <92f4da8e-27a1-7577-84f9-39038eaa88cb@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <92f4da8e-27a1-7577-84f9-39038eaa88cb@huawei.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 29, 2020 at 03:29:17PM +0800, Chao Yu wrote: > > +static int f2fs_ioc_set_compress_option(struct file *filp, unsigned long arg) > > +{ > > + struct inode *inode = file_inode(filp); > > + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); > > + struct f2fs_comp_option option; > > + int ret = 0; > > + > > + if (!f2fs_sb_has_compression(sbi)) > > + return -EOPNOTSUPP; > > + > > + if (!(filp->f_mode & FMODE_WRITE)) > > + return -EBADF; > > + > > + if (copy_from_user(&option, (struct f2fs_comp_option __user *)arg, > > + sizeof(option))) > > + return -EFAULT; > > + > > + if (!f2fs_compressed_file(inode) || > > + option.log_cluster_size < MIN_COMPRESS_LOG_SIZE || > > + option.log_cluster_size > MAX_COMPRESS_LOG_SIZE || > > + option.algorithm >= COMPRESS_MAX) > > + return -EINVAL; > > + > > + file_start_write(filp); > > + inode_lock(inode); > > + > > + if (f2fs_is_mmap_file(inode) || get_dirty_pages(inode)) { > > + ret = -EBUSY; > > + goto out; > > + } > > + > > + if (inode->i_size != 0) { > > + ret = -EFBIG; > > + goto out; > > + } > > Hmm... > > Shouldn't it be: > > if (algorithm >= COMPRESS_MAX) { > ret = -ENOPKG; > goto out; > } > > if (!f2fs_cops[algorithm]) > f2fs_warn(...); Note that my intent with recommending ENOPKG was for it to be returned in the !f2fs_cops[algorithm] case, similar to how opening an encrypted file when the encryption algorithm is recognized but not supported by the kernel returns ENOPKG. For a truly unrecognized algorithm (algorithm >= COMPRESS_MAX), EINVAL would probably be more appropriate. So if !f2fs_cops[algorithm] is now allowed, then ENOPKG should no longer be among the error codes this ioctl returns. - Eric