From patchwork Mon Jun 29 06:50:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 11632287 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B3E476C1 for ; Mon, 29 Jun 2020 20:53:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9AC29206E2 for ; Mon, 29 Jun 2020 20:53:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="uHWduRT5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729415AbgF2UxA (ORCPT ); Mon, 29 Jun 2020 16:53:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731342AbgF2TNX (ORCPT ); Mon, 29 Jun 2020 15:13:23 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D924FC08ECA5 for ; Sun, 28 Jun 2020 23:50:17 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id f139so14961169wmf.5 for ; Sun, 28 Jun 2020 23:50:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/lPkRY5zqjvg98KXV/ewwSSeHltl7MZJ65glZzN0dPQ=; b=uHWduRT5zZJw4Hwc9B74igIqFOEHnjuRsYYMcRLM99cZ1YohKhbSuZsTzU3QNZn5n8 DggURCBqcVH2hKXL67YV8IzP115GSey41KFa0vv0U7Lp2uGwQL6E2xn37o7EOKGWqi+F mXmL71fmVcc9rLdTYLsD4EsduHmkOk/VXC3X9JXq/6Dv9MB06hYXNJlkUYlWqLmPgM5V A23bUylZ1YJ1dXxD6n9hAb81iW4LN5RWRu5oHTSRQKRX7kPnWGRv5t8Ldpq6LkyHTwLS xlWA/+mUQisbhbRJxFYbKpF6wGEKu6IItURDPtgSNDAN1YEwzdnkinovzA2KvpRKJVUq ZmxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/lPkRY5zqjvg98KXV/ewwSSeHltl7MZJ65glZzN0dPQ=; b=BWci/4SNxYFVPYtGQWlzdBcTD4heeNlmpTezufmD9i4fRJjXrPFUkbpF+t0/sCVWJW IzDa6kittP+Qxqq7SlvK8PUWzVS24tv3mrR5ObcT1Te1BVVWYTzGxke8JOCgPFoybVxT ueNjL+U5MOkLi4wpRR1wmciGCceH8n/oqatexOyC9XrlfGX0u9s8OG0wACxzEco9FXbo KVBc089R/w1+S933mL0BTkkok8LCt5KCTM73iqEW62MOG5PyHiDySYp19IQqTxlriTm4 trS5OMpArCx5asDiczX8IKw2uA8tHimb+dhQC+FPtXhQCLIJMa+ygKz94al6qwzFlEx5 E2kg== X-Gm-Message-State: AOAM531bk8znJuDKoTc4Ee6z1tpMs6g3ripfaMf6DiSh4g5DKn+jmdz6 hcmMX8zyCIvJqDIx4egqyfGuAg== X-Google-Smtp-Source: ABdhPJxEvLFDqGizVKVA+kCWvUNxwkMOgwoH94wkn9w50auKmytYRDvwZYMieLGnlarkAN4tua/fxw== X-Received: by 2002:a7b:cf10:: with SMTP id l16mr15384822wmg.93.1593413416631; Sun, 28 Jun 2020 23:50:16 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id z25sm26400850wmk.28.2020.06.28.23.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jun 2020 23:50:16 -0700 (PDT) From: Bartosz Golaszewski To: Jonathan Corbet , Greg Kroah-Hartman , "Rafael J . Wysocki" , Guenter Roeck , Jean Delvare Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 2/6] devres: move the size check from alloc_dr() into a separate function Date: Mon, 29 Jun 2020 08:50:04 +0200 Message-Id: <20200629065008.27620-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200629065008.27620-1-brgl@bgdev.pl> References: <20200629065008.27620-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Bartosz Golaszewski We will perform the same size check in devm_krealloc(). Move the relevant code into a separate helper. Signed-off-by: Bartosz Golaszewski --- drivers/base/devres.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/base/devres.c b/drivers/base/devres.c index c34327219c34..1df1fb10b2d9 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -89,15 +89,23 @@ static struct devres_group * node_to_group(struct devres_node *node) return NULL; } +static bool check_dr_size(size_t size, size_t *tot_size) +{ + /* We must catch any near-SIZE_MAX cases that could overflow. */ + if (unlikely(check_add_overflow(sizeof(struct devres), + size, tot_size))) + return false; + + return true; +} + static __always_inline struct devres * alloc_dr(dr_release_t release, size_t size, gfp_t gfp, int nid) { size_t tot_size; struct devres *dr; - /* We must catch any near-SIZE_MAX cases that could overflow. */ - if (unlikely(check_add_overflow(sizeof(struct devres), size, - &tot_size))) + if (!check_dr_size(size, &tot_size)) return NULL; dr = kmalloc_node_track_caller(tot_size, gfp, nid);