Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp2180956lfo; Fri, 20 May 2022 16:46:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7bxc1TFKAvyDOdkzUx93aL2qFj+xuBuW0bM3C+emp4sNgmR6c0xSAc/SdWh7w64DAL8vs X-Received: by 2002:a65:6bc4:0:b0:3c2:2f7c:cc74 with SMTP id e4-20020a656bc4000000b003c22f7ccc74mr10518499pgw.307.1653090392279; Fri, 20 May 2022 16:46:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653090392; cv=none; d=google.com; s=arc-20160816; b=v1WCiqPoBuHT/FNw8GtVMvriDrBxTaldkn+lX/hu8ih/nirQxKSSin/t8vk+mquI8n ynoB/El+ERvSDIw4wHXboT6KlR6hjRz49NKvydV15STbKS5oUsKlJ/kikRZxWrP0BDHx ulm64auh8qUHLmaGQqxHHtKZPy8bRpZiXCHsFVM1B71BMrlMLalsAe7dgyDesuMbKfMx 29snOWXueIjmKv3+QFAJ4bQd1Pc4L7RGKRcJvmzcBX/mp8WRrVKa6f+Zw9N00f1hbVoU TLHUTh4GHJO6et05j8Cq9KgyUGJCIXyCz0qeWdwu+hyABsLktKna6SGKyqyOEv7DbdqU HqsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=cuhMk4Xj9HrN3ZC1ZjvlsypNYPWvU8txk/gn7Ni0NxI=; b=dpsaiwy9IEyLG/X2HAIrKxr9+wvGHZlaRYtfm8PaYDeLvaVCJJjxhXqW85DrIc13Sh PhAcMKNKGLput5U7vB3DuNfW0PPaeBekQYvbCUKnoniLnMdxXLiDpKdcDr9i15hjazDv WlK8n4PYcFFUeQFSyUL8hlTJeYg7sci7qpzQR+f3K/o3wW8a1CVsdrlh2l2RiZspckeL G7Px2H4SVMGrT9uUBrHmQDbcFaU2LhG1thOJDHQwWoPQiBEQMuWAE/aO27NDPEQbMhwR Z6Y1DNgvEtd8gwJ5LaWFfOHwTZfEZ8zTkNl5bBbooR8r3d2GOsg/ereaJQIrEfDEmDl6 dYYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=tivKm5r1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne10-20020a17090b374a00b001df28d76a0bsi4949910pjb.70.2022.05.20.16.46.20; Fri, 20 May 2022 16:46:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=tivKm5r1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234618AbiESOLp (ORCPT + 99 others); Thu, 19 May 2022 10:11:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239432AbiESOLj (ORCPT ); Thu, 19 May 2022 10:11:39 -0400 Received: from mail-yb1-xb31.google.com (mail-yb1-xb31.google.com [IPv6:2607:f8b0:4864:20::b31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93AFE5C775 for ; Thu, 19 May 2022 07:11:31 -0700 (PDT) Received: by mail-yb1-xb31.google.com with SMTP id i187so7031979ybg.6 for ; Thu, 19 May 2022 07:11:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cuhMk4Xj9HrN3ZC1ZjvlsypNYPWvU8txk/gn7Ni0NxI=; b=tivKm5r1sys75u1UFmvljUq2ee+/9npMFicKjmbSdDcGNEosNVN85RrXMb9Bbvhw+9 yE3rlqmBaJ/4qsfEcmWQVAt8UaA1t9cXhitoz0YsBYWB01qWvoDzoxeadxVxqRFZpNEd 7RdDMocCzFa5iqfLwo7PCo8CAk/oxEf5v7srYmgZikvvwHqdNhDVvJ+VLqLe4s5Vv6ll BYPvBKI1vd96eX+dmY+H+zcSj3wcjEAANgpYJNEhSolg1ncF8ozEGsxcWWn2QeywuORJ klK2ZnfUwSjZoNOz2wjeGlrGNrQWxrKEgetHoPhYmgLw5synMTSDi2Wq9xK/fgLB2A9i s6AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cuhMk4Xj9HrN3ZC1ZjvlsypNYPWvU8txk/gn7Ni0NxI=; b=wBTkLgugUETH3mHLIalf6bFubRCd4KI2Y8R9DHmYIs8xW1TL44BkxapkAA0klHw/oW 6eVGz77y50opUJFQd8BkeYViU3TDdkKrROc2Dd5l9bFXZrAfjymXhLuI3tKEzXMVwMvZ walEL53QyhBcrFwucKKTpw9P9lJZgsMBpmrsGgWS6uTXL6OLjJwldwNtuSAJJ6690ShY ehuYY+zypKIZAwTfYoqeBGTMCKkwouYzChJutFOlr5Pn8aHOgRQncERSXc/WyvqCR2eB jDJlepNmT3SKuO4VhQl4O6ZacYgm/Afrja+/lEwFIUv+sLbrr5aMn4XPtkDIbBiL1Pqk VXZA== X-Gm-Message-State: AOAM532PkYOG/brdfhBqex8OKiEloBvL5o6kqRvGE/p603viEG8YKytw +P2TtAHWfjaDmCKqAM9PbuYP3w3rA7cXPpy83DkWU/lyyVgFog== X-Received: by 2002:a05:6902:4ae:b0:64e:ab25:b745 with SMTP id r14-20020a05690204ae00b0064eab25b745mr4624985ybs.246.1652969490758; Thu, 19 May 2022 07:11:30 -0700 (PDT) MIME-Version: 1.0 References: <20220519125505.92400-1-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Thu, 19 May 2022 22:10:54 +0800 Message-ID: Subject: Re: [PATCH] sysctl: handle table->maxlen properly for proc_dobool To: Matthew Wilcox Cc: LKML , linux-fsdevel , Xiongchun duan , Muchun Song , Luis Chamberlain , Kees Cook , Iurii Zaikin Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 19, 2022 at 9:09 PM Matthew Wilcox wrote: > > On Thu, May 19, 2022 at 08:55:05PM +0800, Muchun Song wrote: > > @@ -428,6 +428,8 @@ static int do_proc_dobool_conv(bool *negp, unsigned long *lvalp, > > int write, void *data) > > { > > if (write) { > > + if (*negp || (*lvalp != 0 && *lvalp != 1)) > > + return -EINVAL; > > *(bool *)valp = *lvalp; > > } else { > > int val = *(bool *)valp; > > Is this the right approach? Or should we do as C does and interpret > writing non-zero as true? ie: All right. We could obey the C rule here. > > *(bool *)valp = (bool)*lvalp; > > (is that cast needed? It wouldn't be if it were an int, but bool is a > bit weird) > If the cast is weird. How about: *(bool *)valp = *lvalp ? true : false; Thanks.