Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp727221ybi; Fri, 7 Jun 2019 16:12:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqyDbm02gyDbH5tpDNJYdwkIIsjmPCP7u51msKnPKHm5KiwQDECijNp4VhX1Ke3bq1gyu153 X-Received: by 2002:a62:648d:: with SMTP id y135mr52661197pfb.98.1559949156323; Fri, 07 Jun 2019 16:12:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559949156; cv=none; d=google.com; s=arc-20160816; b=HRtXuMh89rBee1RWxtSSQ34uaDLLubonLshADdD2652l1FI/BuyJw9rruSBtW8TJ22 NreB8ad4/453Gw6v7T3RSgNxU2Ch71tXASNwcs96nK+NtpctXTakNzmJb4HKEVVBBK4r 3Awoalr86pmx6bcsUS6HRmST+6QahklCMjzzk3RUnHSiHKSesP1QIBILTEW/ULu6zCK0 InJlRFalEYRmgl7sxN0foGBadDX7E9szg0hmVPT2OdiFtQiEXdsVSq8wAuh2UW9QEfcR EDyE30rU+tGPWmLBeQLGD4vb91FHrqvD+cpDVhaib8aTw8VOHx9zVMzczYKo5/5HB6oP Fcgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=OscIWC1H8BYVUTSTRMLtHcpa3RbQBWs93JhulNsk+jk=; b=myqON0XOVmxxZYqIwk6SQPnOs5sOAO3EUXaxIfWPqm0nSFtk3tHKc281b9Um4yUViA EJCgHnwc6kLwxDmxs+K3ZLhqSCUw3xgDls//9ki6vEUsEiNI8NlBEPubvxqRwKXpcyMu wSihFXTvKTc+3dTlZhOx9DHW6eVJI6aPVXJA7bEojSathpLW0UIiIDsT5xIHhydsg3wP 48JdZg7bExdhyTAs9GY9aKDQsIckIhZEcoKx/CU9JJj+BYQOvZLy7486BAb7x9Ox3l9l c5EJJ/O4E4thhC9JGLsvkOxa6CJfpAgeDGZgEYe4wWKoKUAyfXstJAMd+DkOfcS9TRdt ntGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kdR49OFN; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n19si3062382pjo.31.2019.06.07.16.12.19; Fri, 07 Jun 2019 16:12:36 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=kdR49OFN; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731391AbfFGWXG (ORCPT + 99 others); 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-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