Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp312753pxx; Mon, 26 Oct 2020 09:08:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGgQu/dDgAiU5+aDtv5OG10t0ekS7A9/HSsVcyrH63xvMbRX5oRLuvrYPssu/VrDV/mbTO X-Received: by 2002:a17:906:3150:: with SMTP id e16mr16211705eje.266.1603728479762; Mon, 26 Oct 2020 09:07:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603728479; cv=none; d=google.com; s=arc-20160816; b=C0DxLBfBMJP3SuBoB5x6qhMGrX8wvB5EU96ARxC1dT083HNJGEEG0U0hLvWQqKVwc4 w4nkdQJ9xDEap5npGq5W0dQbxE5lmN+7eEKaLk9ldC7Ik5ZWjhcf2qlnp7lorhfA2j/t wsKTMv+H9WqGoVuFzAJOhRuGRleVNxAKmIyA10L3QI0a/+BWHHA9yDDXQoVqhtoNTZ3I MqjmDqf3goeOrw0oH/vhPV2vlZbrx61FV2AOkKifGN5gFqpXlZnmr0lh5iDLRj2PfTWH WIayyTSoBwUvg52ySGWNS0D2hVaCo9T73OUs8yJrmyXQlEUI34/VPHEXUtwTuq1kGj7/ yyqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=0MCnq8BmFjuuQiWlm9eCLlDK+PBQ3cEnax3hxzmA1BQ=; b=VhtTxcBLXrcmoBv0UMjldU3cofhxJyix0yXLYRkda5Iu4lGQRFW8ayqTzKUjwn0DFa +EA6IwwMvXxJG8cs0ax1vGZzVvTkmgONGV5B34nkzRjZUCHYqtEpkR5Y2x/RiV0i9z4H WTEc6ztU8rEVz0IFEFVpspu/yL0lu3ykOnmYjJhCoSCClEIrnt1ZI3bSG4Z5QJj0xSxZ 14RmauIcMqjG85Y9txlfXuRuU0o90GmEExHkBg9r1YmtlOb8kQ9Wp2LSD+2fHj7h9/+V IdZzTOGJLse9bneOrHrRI3MMCCnCGvjVIAXGrV9MXME8ocYaQObD4c+ItxnHlp/mvlk3 PsMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=ar94P11I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ny22si7413690ejb.518.2020.10.26.09.07.37; Mon, 26 Oct 2020 09:07:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=ar94P11I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1775112AbgJZM1i (ORCPT + 99 others); Mon, 26 Oct 2020 08:27:38 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36588 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1775108AbgJZM1h (ORCPT ); Mon, 26 Oct 2020 08:27:37 -0400 Received: by mail-wr1-f66.google.com with SMTP id x7so12285169wrl.3 for ; Mon, 26 Oct 2020 05:27:36 -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:mime-version :content-transfer-encoding; bh=0MCnq8BmFjuuQiWlm9eCLlDK+PBQ3cEnax3hxzmA1BQ=; b=ar94P11IWiyu+ZMvtAZ0o8i4GpU+IiVeYFg89QsdI4Fl/IfyIMiNvV/ZBSWjvk12JL 58V//LBZI+rtWYw0X4Bn2oQNQLHEXiQT+aA1o2ncEPIO5ySDB1Sasg6ygemtGS+Yf6E8 Deuk/6Lq84fTVm91LMKsVd7MT+EPyWJS7L+b6GF4Q7qsSfgMUI+t5nwiDO698lrFFbYG UY6rhFiTw9d+amHmlcN5VPEXfiCbY2b88eOhowYD2Kka+QGuLhT40GFSLTnfNR4mOcSp R6GNaOoy354+YRxF730RTb7Gtu2Yenz4VT+Vp/CMiz0T9gr87B3r8tAE3xpKxj6Rc3TN uW1w== 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:mime-version :content-transfer-encoding; bh=0MCnq8BmFjuuQiWlm9eCLlDK+PBQ3cEnax3hxzmA1BQ=; b=hYUflz0YteTv5DjkIunLsR9uAkAjqEBvEHIyBDWn3Pb3Si0nQthXlAx6IDIhEvC/XY qJP/Lb4/4lZfKu+tXglsROAYxDC7WEAa5Y8X9EYdhnxyu6pUQKwBgn8R6QQCqHPYu//U tdpWC+NjAkhnQCd3tWVM7fQuh3VGkRRWniKNYcvhLjMfTO6q4o8MPbzRLKKOwqtln3dM 9brruFLauKNu19qhiG+CjcKOE0qjgOVcy9XLI4Uc1/K26I9lQCGYYZNjuOERCE+/WLQW S118+m+lesMiAh5HVszIQoQBHQBFX/q0rNcRXfc91bygE6mjmuZwhztu06oHGcDPvd+k a2CA== X-Gm-Message-State: AOAM532ptY9F07EFUqBRojemuQ2w3Vk4TU3kB2utnx8x/bdSokocakQf GE13siYvZYFB0ihOWcMAtXXAxw== X-Received: by 2002:adf:f841:: with SMTP id d1mr17571389wrq.297.1603715255563; Mon, 26 Oct 2020 05:27:35 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-190-206.w2-15.abo.wanadoo.fr. [2.15.39.206]) by smtp.gmail.com with ESMTPSA id p4sm23401025wrf.67.2020.10.26.05.27.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 05:27:34 -0700 (PDT) From: Bartosz Golaszewski To: Greg Kroah-Hartman , "Rafael J . Wysocki" , Andy Shevchenko Cc: linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH] devres: zero the memory in devm_krealloc() if needed Date: Mon, 26 Oct 2020 13:27:28 +0100 Message-Id: <20201026122728.8522-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski If we're returning the same pointer (when new size is smaller or equal to the old size) we need to check if the user wants the memory zeroed and memset() it manually if so. Fixes: f82485722e5d devres: provide devm_krealloc() Signed-off-by: Bartosz Golaszewski --- drivers/base/devres.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/base/devres.c b/drivers/base/devres.c index 586e9a75c840..e522ad5f8342 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -895,8 +895,12 @@ void *devm_krealloc(struct device *dev, void *ptr, size_t new_size, gfp_t gfp) * If new size is smaller or equal to the actual number of bytes * allocated previously - just return the same pointer. */ - if (total_new_size <= total_old_size) + if (total_new_size <= total_old_size) { + if (gfp & __GFP_ZERO) + memset(ptr, 0, new_size); + return ptr; + } /* * Otherwise: allocate new, larger chunk. We need to allocate before -- 2.29.1