From patchwork Tue Dec 19 22:28:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 181318 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2273541dyi; Tue, 19 Dec 2023 14:32:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGMogYgYv6Ib8dW5k6P5Df33aS54UQSo/rHvMNwOsUpoTvLujWK0v+HMFE1JtVvqQUlARVA X-Received: by 2002:a17:906:b245:b0:a23:5eac:181e with SMTP id ce5-20020a170906b24500b00a235eac181emr889100ejb.258.1703025133039; Tue, 19 Dec 2023 14:32:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703025133; cv=none; d=google.com; s=arc-20160816; b=HLldi81gTONwzalgCGruJ6VfkKU84ZWGMXypTHhvyz/xcP7xc6Ar+7HN0kRVT6NTzo ueOdzZokaFbg3a/vXz6j7UDNjGrJw8E1a2Z+7QzccK4+U4Ez9gInI7NAFhZ6sSU79LtV 7Zq99cSn+dGJRPukOe/09dNlt7owy2dwtgoKQjKGSmaMawzsPvGKQIKYkQJDtYb+rDcQ sG9oAQINBAzCLy3ipr5fVRm76FUcq39L88J5DxbqTefLJ7y+spJd7DK3iR9ru5m2aMcX 6cBaeJogsoj0YJbioU7PamL6AN+EfXe485EwImum7N50JtFJhw1w/MBGP5Ck5T+P/upo UxLw== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6048-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w15-20020a170906480f00b00a236ad88211si1396728ejq.564.2023.12.19.14.32.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 14:32:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6048-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6048-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id A39C91F258B2 for ; Tue, 19 Dec 2023 22:32:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D5F842064; Tue, 19 Dec 2023 22:30:31 +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 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785751281569838581 X-GMAIL-MSGID: 1785751281569838581 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)