Received: by 2002:a05:7412:d008:b0:f9:6acb:47ec with SMTP id bd8csp216513rdb; Tue, 19 Dec 2023 14:31:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IH8OFAxcxtOJDwaqL+rOftaLsRB/PXdEVW3984hWEcPuC1P1TXqXRo9/Jq71Y1TAKfb+MWc X-Received: by 2002:a17:903:443:b0:1d3:b856:203a with SMTP id iw3-20020a170903044300b001d3b856203amr2225103plb.78.1703025082321; Tue, 19 Dec 2023 14:31:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703025082; cv=none; d=google.com; s=arc-20160816; b=yQrKyYPvsk3SrK0GxhAoi3q1onqY0+IDOvwsUJvn2zP5AfLvM+LXkSSh2h3rRj0omj Bkb6lS4sN3IQFLIcaYHX75GW1fPIFsRtumJZpkkc0IuVgnHU0ibEz3oNGq1+36bVM9dN 1LHRpDUF735t9tdWZbcx3S8zDvgp2gZ5iPnIHq5fPf4/F+dGYR879LShp7Ztqea2ycu2 yL9uW600KtpQOb4d5dYKwfGLoY4SMSm5lbY5bpetyhVHzx9SNu18qP8eW7RIYp0hwgTw fL8fzJZPdDg5VYLedtVaApq2JQ4wlf8089Vn01SJfJzfZ3FZjzI15BfRXXCfUMmsYrle 6nvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=xReOl/oREsxJLQ8k6aIhVhARLuZMnM3hsCknlxTDelk=; fh=AIzsiqkKUtrB7QnM+XRgAblgvDINIC5pDvD0mg8EzrU=; b=Ul/FVgZofAsYMl8xvpclS8DGs3sLktNRsUOfVMYgZzU+Ks2Jrks2a+iDq/+6G1m/MS bX2zU5jB4oVrZ7ZpUg42xPc1rITwOZgePVE8myGVEKPTHuk7+kbFoUftKRl4CpMztQ0k eFrZP/7ZHtFzxzviZpW8UQ5SALle+gSAyRyHYo3dT8hNYsRzW/zglBghjwxbr4jE5Lxp KFE9mmOyNdym7epV3zAw0cwJck9moFHbi+9XBZJVe7/OLyTqaEpNwoNoB+vjPk3af+WB 6c1iX5wGH8KyyXZH7Cf0SsAPlntRWjCIHXDLHDzRYqiPTgEMe0A5cHJG84FSG/Lk1nUU bvHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=aMTrQUR0; spf=pass (google.com: domain of linux-kernel+bounces-6048-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6048-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k17-20020a170902c41100b001d3ad3ec005si4953794plk.311.2023.12.19.14.31.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 14:31:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6048-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=aMTrQUR0; spf=pass (google.com: domain of linux-kernel+bounces-6048-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6048-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id F2747285689 for ; Tue, 19 Dec 2023 22:31:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D36E63FE2C; Tue, 19 Dec 2023 22:30:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="aMTrQUR0" X-Original-To: linux-kernel@vger.kernel.org Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9E423C6AC for ; Tue, 19 Dec 2023 22:30:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1703025019; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xReOl/oREsxJLQ8k6aIhVhARLuZMnM3hsCknlxTDelk=; b=aMTrQUR0xLK7BplxYFtE4/Xbs25JDCetJWE5YR0p8XlsH+LA6uU4fkxqdQROa6y+LmxS6E H6/bMd8AJ43AJZtjVMsIrilr90PtruFOb4TzM1ChHIK5W2TnGpASFi8QvV447DisyRfhwH u+nqgpjQtRh+bJSPL6UUsX9RcwPAdbI= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Evgenii Stepanov , Breno Leitao , Alexander Lobakin , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 08/21] kasan: clean up __kasan_mempool_poison_object Date: Tue, 19 Dec 2023 23:28:52 +0100 Message-Id: <4f6fc8840512286c1a96e16e86901082c671677d.1703024586.git.andreyknvl@google.com> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT From: Andrey Konovalov Reorganize the code and reword the comment in __kasan_mempool_poison_object to improve the code readability. Signed-off-by: Andrey Konovalov --- mm/kasan/common.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 7ebc001d0fcd..3f4a1ed69e03 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -457,27 +457,22 @@ void __kasan_mempool_unpoison_pages(struct page *page, unsigned int order, bool __kasan_mempool_poison_object(void *ptr, unsigned long ip) { - struct folio *folio; - - folio = virt_to_folio(ptr); + struct folio *folio = virt_to_folio(ptr); + struct slab *slab; /* - * Even though this function is only called for kmem_cache_alloc and - * kmalloc backed mempool allocations, those allocations can still be - * !PageSlab() when the size provided to kmalloc is larger than - * KMALLOC_MAX_SIZE, and kmalloc falls back onto page_alloc. + * This function can be called for large kmalloc allocation that get + * their memory from page_alloc. Thus, the folio might not be a slab. */ if (unlikely(!folio_test_slab(folio))) { if (check_page_allocation(ptr, ip)) return false; kasan_poison(ptr, folio_size(folio), KASAN_PAGE_FREE, false); return true; - } else { - struct slab *slab = folio_slab(folio); - - return !____kasan_slab_free(slab->slab_cache, ptr, ip, - false, false); } + + slab = folio_slab(folio); + return !____kasan_slab_free(slab->slab_cache, ptr, ip, false, false); } void __kasan_mempool_unpoison_object(void *ptr, size_t size, unsigned long ip) -- 2.25.1