From patchwork Wed Jun 7 06:18:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 9770587 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4E84160364 for ; Wed, 7 Jun 2017 06:18:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3979B284A6 for ; Wed, 7 Jun 2017 06:18:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CA8D284D2; Wed, 7 Jun 2017 06:18:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA20E284A6 for ; Wed, 7 Jun 2017 06:18:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750920AbdFGGSV (ORCPT ); Wed, 7 Jun 2017 02:18:21 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36429 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750730AbdFGGSV (ORCPT ); Wed, 7 Jun 2017 02:18:21 -0400 Received: by mail-pf0-f194.google.com with SMTP id y7so592758pfd.3 for ; Tue, 06 Jun 2017 23:18:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=VqpO8jbd7xnJcgr+Q8cEQpkJgqZv5/yzc8j0Dcv72aU=; b=os5ySbHrvP2DQorK01LJu6j5cFlyDUgzmupIQQ2DSn4j+mkpINFm9rurthdN88ps/c MOiiJtsPT4Dbkhvj/4EjcyuZSdsfbhdAkTi0BJ0Q2zBbrN3SBLx6upUznnVEvBwpYlUK rsjJr5RD8Ha5rX7BhKb/kqPtkrLYyNOYGYje8oRUD+5f8xyVRcbp8nYwyZWiM7oY4T8Y XOWs4ln+e9L6ZPYC6JjVMs3kemEQek5qdZJFi5xpnaenMTHtXp7lyaCTQaRM+4IaDBae LUoBjJ4Tr+MLXRQxMxiLp4mN27WCK9FxfdXIrrogMjMmtLIZDRLqS2u42K+/+k2KNVv7 tCHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=VqpO8jbd7xnJcgr+Q8cEQpkJgqZv5/yzc8j0Dcv72aU=; b=RdmE9aXidBx+y5NozPfZKJRfV3fxV60z4I6C1W1gofKDsw0NNS5YX68X8H6RJWLT5V 224pf7guEhJEpJg7L28pgEndM3p4xYwNmHYqhk1O2Z3E2Sz2fIK/FDTg/2jG/4Ly2hyH dyfSada/oEKaoZkPGRXQQ0a743dUT/iOCK+lpe/JefRJvPCwMKUNjzCRGzBBXL0RMY1i uYCnKZu3GPL1VINVzJc/yo3v0Az41f+ebrrEcTPyTteoxLrH8d2bkZtFhlW0Umk01/i/ uiCkxIzilJGkiHS/Kn6OAdU76Q7LXmBwUszdu/EGCVuQRh4dPwkqL4pxYgysDpnWRi2M GK3A== X-Gm-Message-State: AODbwcAg3GzFlzjqRzWcDWFikCLuvwz4Iex2vWXxPIrx0D/A/vLPkkeD uWW63KRaUBFA/GADkY9RzA== X-Received: by 10.98.63.218 with SMTP id z87mr20617937pfj.144.1496816300348; Tue, 06 Jun 2017 23:18:20 -0700 (PDT) Received: from aurora.jms.id.au ([203.0.153.9]) by smtp.gmail.com with ESMTPSA id n2sm1326914pgd.26.2017.06.06.23.18.17 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 06 Jun 2017 23:18:19 -0700 (PDT) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Wed, 07 Jun 2017 15:48:14 +0930 From: Joel Stanley To: linux-modules@vger.kernel.org Cc: Stewart Smith Subject: [PATCH kmod] util: fix non-static assert_cc use Date: Wed, 7 Jun 2017 15:48:11 +0930 Message-Id: <20170607061811.4016-1-joel@jms.id.au> X-Mailer: git-send-email 2.11.0 Sender: owner-linux-modules@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP In commit a6ede6c7ad46 (util: fix warning of equal values on logical OR) the runtime check for EAGAIN and EWOULDBLOCK being equal was converted into an assert. For the case where the compiler supports _Static_assert, this is can be called staticly. However the fallback for older compilers uses a non-static test that needs to be called from a function context. Move the assert into the functions that used to have the runtime check. The test does not add any runtime overhead, so it is fine to duplicate it. Tested with and without HAVE_STATIC_ASSERT defined using GCC 6.3. Signed-off-by: Joel Stanley --- shared/util.c | 4 ++-- testsuite/test-testsuite.c | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/shared/util.c b/shared/util.c index 9de080aabb18..c402953b4699 100644 --- a/shared/util.c +++ b/shared/util.c @@ -49,8 +49,6 @@ static const struct kmod_ext { { } }; -assert_cc(EAGAIN == EWOULDBLOCK); - /* string handling functions and memory allocations */ /* ************************************************************************ */ @@ -200,6 +198,7 @@ ssize_t read_str_safe(int fd, char *buf, size_t buflen) { size_t todo = buflen - 1; size_t done = 0; + assert_cc(EAGAIN == EWOULDBLOCK); do { ssize_t r = read(fd, buf + done, todo); @@ -225,6 +224,7 @@ ssize_t write_str_safe(int fd, const char *buf, size_t buflen) { size_t todo = buflen; size_t done = 0; + assert_cc(EAGAIN == EWOULDBLOCK); do { ssize_t r = write(fd, buf + done, todo); diff --git a/testsuite/test-testsuite.c b/testsuite/test-testsuite.c index 56e73609f204..5bafc6551a23 100644 --- a/testsuite/test-testsuite.c +++ b/testsuite/test-testsuite.c @@ -88,6 +88,7 @@ static int testsuite_rootfs_open(const struct test *t) { char buf[100]; int fd, done; + assert_cc(EAGAIN == EWOULDBLOCK); fd = open("/lib/modules/a", O_RDONLY); if (fd < 0)