From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_DKIMWL_WL_MED,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F5B7C2BCA1 for ; Fri, 7 Jun 2019 22:23:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 00C02212F5 for ; Fri, 7 Jun 2019 22:23:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kdR49OFN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731534AbfFGWXG (ORCPT ); Fri, 7 Jun 2019 18:23:06 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:39057 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730445AbfFGWXF (ORCPT ); Fri, 7 Jun 2019 18:23:05 -0400 Received: by mail-pl1-f193.google.com with SMTP id g9so1327386plm.6 for ; Fri, 07 Jun 2019 15:23:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OscIWC1H8BYVUTSTRMLtHcpa3RbQBWs93JhulNsk+jk=; b=kdR49OFNsFx7GSx/8YCa4OAXnuGm9wR3mA3FGM2j9z9kYOvNzqrt6gDMUmNTCF4V83 UuY0GuaC7cU7suXulXpVOn5N4HicehNGLM2Gv1N1iXUCkOIxaL4tP0q7CFg3Zr0ELRoH c1K2fAfx/OZnoqY6EocLtP4K2Gyk7fJHcbAd5+nbSwsumoNC9uZdy1ZbqRPl2ZGb2KR0 5790YANxN6yo4XDpToutn8HtDWJ9qc4x2RtxrkIe4yf2ys4A7CKPGFlNlR6vaeXcDbDI eCRkI67w15jEuFPGTFzQI8EIXARxKyvN1+GR9F9Qoev+vDDjbBqEj+ZoKNPmKxLF0J5U DgLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OscIWC1H8BYVUTSTRMLtHcpa3RbQBWs93JhulNsk+jk=; b=OGpZjBQqA0pI8bvq8Q9XqD6rILlQIca/x1yHYIcrAPBtNp6ud5YVFL6QqFwTVAetrs 5lgCcWZlKgXNtPDkfO5goLJL2BfT8ZJpxZo8mz1BYyZQyuMv2SFwHqhmg5kTzrB/JJT1 EnF8iOYTYbkjHUsKjXms4DEgb4gkvV3CLiBi5Xtq+whUbi3KsiWRzxClOOjyOQ8ddUxu VhPD6RGscSO0Eb61UEWoOZluZHAzfDitBW5PoM5Q8iLToRJi4Ph0V3NSf+HmRo6KSUJl FCQ/YkQGAwiLS+Bafmb9smA6HmZncMyvbkN7uPhpj/Wc04bnpnF+bnck9+r4CkQLubUl nBKA== X-Gm-Message-State: APjAAAXboFD3g5iEr2ddqpF/6+9VcPxd33kDCPzZngtFgZTk9fgmBJE3 F8z+fG75EfH6j6Sw5+q9dQW9FLWBr4B8Yh4QX3XHYw== X-Google-Smtp-Source: APXvYqxqRVfuyQEdyfJNNkPVX/y1rXYgnEMZVKj/CtJa0Fm8bihW1BebEYmymKIH0C8/tAoxb6DpKUorgA1wvW4QAXM= X-Received: by 2002:a17:902:624:: with SMTP id 33mr59045206plg.325.1559946184199; Fri, 07 Jun 2019 15:23:04 -0700 (PDT) MIME-Version: 1.0 References: <20190514221711.248228-1-brendanhiggins@google.com> <20190514221711.248228-18-brendanhiggins@google.com> <20190517182254.548EA20815@mail.kernel.org> <20190607190047.C3E7A20868@mail.kernel.org> In-Reply-To: <20190607190047.C3E7A20868@mail.kernel.org> From: Brendan Higgins Date: Fri, 7 Jun 2019 15:22:53 -0700 Message-ID: Subject: Re: [PATCH v4 17/18] kernel/sysctl-test: Add null pointer test for sysctl.c:proc_dointvec() To: Stephen Boyd Cc: Iurii Zaikin , Frank Rowand , Greg KH , Josh Poimboeuf , Kees Cook , Kieran Bingham , Luis Chamberlain , Peter Zijlstra , Rob Herring , shuah , "Theodore Ts'o" , Masahiro Yamada , devicetree , dri-devel , kunit-dev@googlegroups.com, "open list:DOCUMENTATION" , linux-fsdevel@vger.kernel.org, linux-kbuild , Linux Kernel Mailing List , "open list:KERNEL SELFTEST FRAMEWORK" , linux-nvdimm , linux-um@lists.infradead.org, Sasha Levin , "Bird, Timothy" , Amir Goldstein , Dan Carpenter , Daniel Vetter , Jeff Dike , Joel Stanley , Julia Lawall , Kevin Hilman , Knut Omang , Logan Gunthorpe , Michael Ellerman , Petr Mladek , Randy Dunlap , Richard Weinberger , David Rientjes , Steven Rostedt , wfg@linux.intel.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 7, 2019 at 12:00 PM Stephen Boyd wrote: > > Quoting Iurii Zaikin (2019-06-05 18:29:42) > > On Fri, May 17, 2019 at 11:22 AM Stephen Boyd wrote: > > > > > > Quoting Brendan Higgins (2019-05-14 15:17:10) > > > > diff --git a/kernel/sysctl-test.c b/kernel/sysctl-test.c > > > > new file mode 100644 > > > > index 0000000000000..fe0f2bae66085 > > > > --- /dev/null > > > > +++ b/kernel/sysctl-test.c > > > > + > > > > + > > > > +static void sysctl_test_dointvec_happy_single_negative(struct kunit *test) > > > > +{ > > > > + struct ctl_table table = { > > > > + .procname = "foo", > > > > + .data = &test_data.int_0001, > > > > + .maxlen = sizeof(int), > > > > + .mode = 0644, > > > > + .proc_handler = proc_dointvec, > > > > + .extra1 = &i_zero, > > > > + .extra2 = &i_one_hundred, > > > > + }; > > > > + char input[] = "-9"; > > > > + size_t len = sizeof(input) - 1; > > > > + loff_t pos = 0; > > > > + > > > > + table.data = kunit_kzalloc(test, sizeof(int), GFP_USER); > > > > + KUNIT_EXPECT_EQ(test, 0, proc_dointvec(&table, 1, input, &len, &pos)); > > > > + KUNIT_EXPECT_EQ(test, sizeof(input) - 1, len); > > > > + KUNIT_EXPECT_EQ(test, sizeof(input) - 1, pos); > > > > + KUNIT_EXPECT_EQ(test, -9, *(int *)table.data); > > > > > > Is the casting necessary? Or can the macro do a type coercion of the > > > second parameter based on the first type? > > Data field is defined as void* so I believe casting is necessary to > > dereference it as a pointer to an array of ints. I don't think the > > macro should do any type coercion that == operator wouldn't do. > > I did change the cast to make it more clear that it's a pointer to an > > array of ints being dereferenced. > > Ok, I still wonder if we should make KUNIT_EXPECT_EQ check the types on > both sides and cause a build warning/error if the types aren't the same. > This would be similar to our min/max macros that complain about > mismatched types in the comparisons. Then if a test developer needs to > convert one type or the other they could do so with a > KUNIT_EXPECT_EQ_T() macro that lists the types to coerce both sides to > explicitly. Good point. I would definitely like to do this, for me it is only a question of how difficult it would be to make all that happen. We will investigate and report back on it. Thanks for the suggestion! It's a really good idea! Cheers