From patchwork Mon Dec 9 16:57:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13900060 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D468E7717D for ; Mon, 9 Dec 2024 16:57:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 940BF8D008C; Mon, 9 Dec 2024 11:57:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C6888D0058; Mon, 9 Dec 2024 11:57:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B6268D008C; Mon, 9 Dec 2024 11:57:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 520428D0058 for ; Mon, 9 Dec 2024 11:57:50 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C7F371C7111 for ; Mon, 9 Dec 2024 16:57:49 +0000 (UTC) X-FDA: 82876026996.05.1EC54CC Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by imf06.hostedemail.com (Postfix) with ESMTP id 41CB1180017 for ; Mon, 9 Dec 2024 16:57:33 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Zl0a1Cfo; spf=pass (imf06.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.215.170 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733763453; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sUP+2JyKnLRQco8QsCJe4ce6gkYVIGp7F338G8iPtHg=; b=GhxXxLRPVkHB0X6WGUTIUj/n3s+W0RqRjHjDEjIUCCgUE6k9F//5fDENl/Zkzi7Q/jRwU7 C52ceZiDMD/rVMoVzQJFlTw2btxyIduenVDzcSNCgg3s+TjDPeROkLTBYzWBA6avsheBMF qUW2+VTqC6Qj3/QmjSJ/rrNeWXj1i4E= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Zl0a1Cfo; spf=pass (imf06.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.215.170 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733763453; a=rsa-sha256; cv=none; b=W25PhAsnkTi20BIWMsbQMRfP5dJLvCWaX75ICQZu431GrQ1XKha4uTFZmlotJKZVi0CLmw IOIgnxW2Qy6EDW0hiFGOBB9j0jdml7FGg0Zm2/UKsoKEJL5+OO2Vq34lvyFiz/wk6nJz0P iFgYvMLnXk9878z/Mf/HilT/cqyG40o= Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-7e6cbf6cd1dso2566171a12.3 for ; Mon, 09 Dec 2024 08:57:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733763466; x=1734368266; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=sUP+2JyKnLRQco8QsCJe4ce6gkYVIGp7F338G8iPtHg=; b=Zl0a1Cfo25m+BWVA7agj87epqVa4IaeqzeiPFfdTNfECn7KOHsxBupyrjP3dbG6lzw 2JeIj6GF3VaK0RB3spaPxmOBnUHtOq0Z68ODJTX1msg5ZyYpuDetkA8JUhJs8hm3tWm9 ehZNa6ix1nc8IxdxJbMhqjlRInrfUN6+sN6knAu52PufO6XIpJKlm4kr4JbIXgPVEAMf 6DBZB6Ta61KaCacGtAZV2Lf8d68fMMGuS3J2Q9f//nMGhXmGAJ5Inqagp2AAnUxtP1gN 24/778eoGbbjZAuCeGAQ7dohd4kQvx0lGRwLrdiDVx0N40/BrPLwY7+nBkfqkbLscchN 7NYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733763466; x=1734368266; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=sUP+2JyKnLRQco8QsCJe4ce6gkYVIGp7F338G8iPtHg=; b=bQpYh7OMSYrbO1P9pX7XUtcIsPP/QyMu/IeaozraH7gazL/4Oi8aG2qnRnrKzYXGjw WwuVjvpeJvDSod2wQDZU4+1fD1QxL6IEIAu8fcWCbBccKdDdwtYVNLxGcvNQf78a9Rk6 fxLVR5sJHBaGJuEPnEpAJW+aCl/tSj2RMDwRXqPuGjsahP4wbTvfqy+qjvLJzKSREbNH uCMq5eGyi1e5uSVyd5MygZog6ihSpThS0d4LMPqngQAP5LG7/P3onevxp8fToX4HkM5t 9dbZCgPDmiNOVZKlHk7QGzIHciR+WFvChDfQ6nW82Zw/QgQ8bdrpNgyccoI54aAFVvRC K23Q== X-Gm-Message-State: AOJu0Yyny5tPn83oRdaUJMwEgcRMO2+aIH410fHuo55/FoWAzHFOeZzK 8AgqEfmbBKTtqdn8vzet7oRr+bF3iNn0AFDFr7ZFNFE0XCvbC2hepwJkPaHI19gExg== X-Gm-Gg: ASbGncs2yo4AolIWeZYE+zgQg4Ep5j2GB7UDyJaQ0hkc6zLHwDm7tae28fJW9bltzy1 Kba7BObbVjTEPFVjKTkddh8/b8Oy3psC+N94jo3pWjIVtK8dW7Q+MpukATooQCLJKRtNP7lW9Ed KBzEQqX8tgt4gPzgH1pTpoJvvEu8SO+Ze+egB0Cz7zOQubzfWOmjM+c2I0KNP9kmJdIhgD54ykw O4dYQA17NDWP/G5ubeN4W8IStUtihRQp16Vbnop4S5kfZEunRaAHa9NtAUr0VJ0XFdqx04= X-Google-Smtp-Source: AGHT+IFU9XNL4TYYMN57+MI1JthzbOjTs3oeXC9tvV2S1ujsyt7L/AjZO37t5fVZBxfj6fd+QgbvFA== X-Received: by 2002:a05:6a21:e88:b0:1e1:a6a6:848 with SMTP id adf61e73a8af0-1e1a6a60975mr9194204637.25.1733763466179; Mon, 09 Dec 2024 08:57:46 -0800 (PST) Received: from KASONG-MC4.tencent.com ([106.37.120.120]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7273c7f3f1fsm514201b3a.13.2024.12.09.08.57.43 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 09 Dec 2024 08:57:45 -0800 (PST) From: Kairui Song To: linux-mm@kvack.org Cc: Minchan Kim , Sergey Senozhatsky , Andrew Morton , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song , Desheng Wu , stable@vger.kernel.org Subject: [PATCH v2 1/2] zram: refuse to use zero sized block device as backing device Date: Tue, 10 Dec 2024 00:57:15 +0800 Message-ID: <20241209165717.94215-2-ryncsn@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241209165717.94215-1-ryncsn@gmail.com> References: <20241209165717.94215-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Stat-Signature: b51edqyfa6pey117sotcu1tdwy39ogf9 X-Rspamd-Queue-Id: 41CB1180017 X-Rspam-User: X-HE-Tag: 1733763453-393565 X-HE-Meta: U2FsdGVkX1/4/QOB7OKqIcskYaAWszpauKH4RN/FQXGDww6HV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IWnnMNOY5O708BQP7KBnG9Is9O1c3u9DU9fKOVX5vovqDyBE4C8qZ44a+/HFHWVCPMC8AQVvtOs8rd4X8vxcnhdJUf/tlXAD7NgAhAQeb9BdTOF9inVwLaVJzk1SI2E6b5JuAwoszgK7l5gBG80jhntS6mlAjzrsQFKMKC0HajPQ3mpafEtUoV1wy7SQ1LOw29KS2myp9wGtktZ7w7k4VjQ/D2Rlyoa7Rr53Xgb0yXzDusngQ6tafGIgioGAeCyAh6u7PnPS8GV7bw0L6DcZHE87Hv14RM8nojDdJiXfxEBT2N20JgotyZu0YwQoucwXpSMIMT7AUerh18vTcsXhwqNnWFHJPyFz3HB6iCvrPWa33L3DYFLUuwBVor0A1UCuyjCNLa6tH/wuynXSdqZdZ2PfXm0hbAWZ1Q0ZqXnVhfF25f3LsFrxJ/Jm8n9t1Vn X-Bogosity: Ham, tests=bogofilter, spamicity=0.064919, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Kairui Song Setting a zero sized block device as backing device is pointless, and one can easily create a recursive loop by setting the uninitialized ZRAM device itself as its own backing device by (zram0 is uninitialized): echo /dev/zram0 > /sys/block/zram0/backing_dev It's definitely a wrong config, and the module will pin itself, kernel should refuse doing so in the first place. By refusing to use zero sized device we avoided misuse cases including this one above. Fixes: 013bf95a83ec ("zram: add interface to specif backing device") Reported-by: Desheng Wu Signed-off-by: Kairui Song Reviewed-by: Sergey Senozhatsky Cc: stable@vger.kernel.org --- drivers/block/zram/zram_drv.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 3dee026988dc..e86cc3d2f4d2 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -614,6 +614,12 @@ static ssize_t backing_dev_store(struct device *dev, } nr_pages = i_size_read(inode) >> PAGE_SHIFT; + /* Refuse to use zero sized device (also prevents self reference) */ + if (!nr_pages) { + err = -EINVAL; + goto out; + } + bitmap_sz = BITS_TO_LONGS(nr_pages) * sizeof(long); bitmap = kvzalloc(bitmap_sz, GFP_KERNEL); if (!bitmap) { From patchwork Mon Dec 9 16:57:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13900061 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B8CAE77180 for ; Mon, 9 Dec 2024 16:57:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DAA3A8D008D; Mon, 9 Dec 2024 11:57:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D5A908D0058; Mon, 9 Dec 2024 11:57:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD44F8D008D; Mon, 9 Dec 2024 11:57:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9EE438D0058 for ; Mon, 9 Dec 2024 11:57:58 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id AB29E1605E5 for ; Mon, 9 Dec 2024 16:57:52 +0000 (UTC) X-FDA: 82876026954.30.0B8F8C7 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf12.hostedemail.com (Postfix) with ESMTP id B198440009 for ; Mon, 9 Dec 2024 16:57:41 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=H+Jc+k3l; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733763461; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TWIw0hhAH4VJQ0Z+LUoADX7ca43ciXjofF1Ce/M4dOk=; b=Ohesf4fyh/bDYBUFowi6E6KpCO0ikLkRaDSth4v+U855Usc22BJQvESxwfqOAEyd1u1BBV /ydorTzVFHm+cSu8xdmUdxyH90f9sU4vS2goB22phteaMqEpSqbGg9soMy9lUxV9pOtsP2 ZGiD1wWWMkkngStmzq/8rwUc+vVreOo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733763461; a=rsa-sha256; cv=none; b=3xVY3gK8DB/v1Vux/KDSLVYY8mDpJFlTLFRLbKicKRvFRU6QeGzOWNjTOzd0YUM1iJhZEV +/TQSK2SlN8PVGRnBlI9g1zDl/PZ1tXcajPJp3VvURxZt3geVXb4/zG/v0thDYQ+opjG3h wGrcRAggjDZ6lKM6ZbwTQYohFto9e6A= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=H+Jc+k3l; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=ryncsn@gmail.com Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-725ee27e905so1286051b3a.2 for ; Mon, 09 Dec 2024 08:57:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733763469; x=1734368269; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=TWIw0hhAH4VJQ0Z+LUoADX7ca43ciXjofF1Ce/M4dOk=; b=H+Jc+k3lt8fMPy9gfxU2PmaWfIgYOeJqrzN9ICQgDM7csIx/Cxz96RzRFNdOGW9eJP aJtfkpVV5MzWZwfSFEdJNbfdx18vyO52qB0oNDrK4Z5anie13EBNYzEy6SRio+DMpd95 V3rchKpPP2yHb88WOyuBvjrZvaD6i0rRXq/EZdTYl7MMy39F2H4B351VW/psSAmS8Hb0 BGR8SUevucuXCp/pEw4nx5iWkZ5lkxIqVa2k23fHT/pws17GckxVuXAVlsjsA8NMapsp gqUIWDKdQP/HbLYmA27jbFDIv2/a+dsuHDwIzQOTSo2I1lfPl4hLIDXtbyX7JK3sU20s RiQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733763469; x=1734368269; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=TWIw0hhAH4VJQ0Z+LUoADX7ca43ciXjofF1Ce/M4dOk=; b=ECo7PV2nF2KrJgHl69F3bi8KjixObxtVAnOV/h0aMSSsxyq2QHJofSwSelBqK+BhY3 nIlKrewQwRRahssTlc2onQzyVhgxeeKZaOSv4Ea9IXsWrHQT5bZE0mJGDzcHS1fQSZcp OUinpu1gf/gE5glbuqiCrdZyWsYkAZbxWxbxIVxcD3WobmEz9/F8exK6MNYvKQOKilyw O8chK/0qvKHJUqxS/uMbepywtBw8DMXnIjg0ECp2CppMmc14rSmVdkD08yaRT6e1Vx8U 3VumGOHBPE9BJL+4h+2cax73ugbIeyBjGNL0KpwgR10u4AJiKGnmP5u0xbQBfrxeVYrq 4wuQ== X-Gm-Message-State: AOJu0YwWZBaS+AWgCnBjcOqKfTI4R1ATvWsO0muF1Nw9XRPCgC6fP6mv qNIBYGupKH0wL5SBe2BpV9GXOR1OfHnFl7sCLVE9AD6s6zhn3sSwyNMhpbk1BtIAow== X-Gm-Gg: ASbGncujvi+qpLA7urVkPcDPHru4gWfqxMS9ffrsZIWgx5YC3Rhw1r2fxNNPeuG4uZH vxHOHlsTvJodxvtrNhCguYY3aRTaHHGSodBjcg3ol5bYCSfZ/moAz03OVo0tmB8JSL0PGrhuV2Z gRYZgMbZDEQX8X1RKCK6JbgJq54QAq3pj9ruyphsIGqVDG5hVSiMf0gVsuJDxRRMvupGl/Ep33U zgCCxijKfVOpBV8aQIcqPv06wle2klaWRKB0rE41o7NfZNusBuy2NTYsqCqx224/zRii/I= X-Google-Smtp-Source: AGHT+IGPb5h1KzA7h2yK1etF1SPW3948xDox8qr2YCpFm0ctolrhSkaAbYueqzrsyOSh5QsXCLFdsg== X-Received: by 2002:a05:6a00:2e0f:b0:726:f7c9:7b28 with SMTP id d2e1a72fcca58-726f7c97e8emr3032663b3a.8.1733763468992; Mon, 09 Dec 2024 08:57:48 -0800 (PST) Received: from KASONG-MC4.tencent.com ([106.37.120.120]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7273c7f3f1fsm514201b3a.13.2024.12.09.08.57.46 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 09 Dec 2024 08:57:48 -0800 (PST) From: Kairui Song To: linux-mm@kvack.org Cc: Minchan Kim , Sergey Senozhatsky , Andrew Morton , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song , Desheng Wu , stable@vger.kernel.org Subject: [PATCH v2 2/2] zram: fix uninitialized ZRAM not releasing backing device Date: Tue, 10 Dec 2024 00:57:16 +0800 Message-ID: <20241209165717.94215-3-ryncsn@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241209165717.94215-1-ryncsn@gmail.com> References: <20241209165717.94215-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Stat-Signature: b8d5hazhc43oojtqrioca1n3rj6fuhzq X-Rspamd-Queue-Id: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e9xVJNSWrRgwb4PpFz/DlSUawF044HfewwcvZ8y9mNbpPqYtnt/tbb8NEPClsjLps1OpS3QlMjW4Q/47X2gp5+a3Z26Qqj7er8cj23LnZrk2EEb9LkaTScG8kLDGz6+YDT5PINhJUqdoi47uCKEoRBPJMKQERidRSR1/BIqwdCMiiArR7TYtMDm10f4x/UAnGEr9+o17FH/ujF9jXiZbCmJg8A+5egPZgvODWHfFjOKCCqsds1nJvmdz+cvHGw8Eu44HVpnUcV+AqqSt1S8YP1jAsK1zRfQLaDCdE893A4HtrTeh+/qDxW069OX5tqv7ZBSM6k7usp916uZs1pzXeJwsus2bKucO7XXLetp2rVifOrVDGXcYZY0VE1X+BKXNPITm9M6GFL6JJ8hOYT+GMk/Z7Cv6LgFfwTpMVW2ziT4OD5YAX4UVIyZ7M2NW7pWTatXVXRr/gEBFQUV81pri/gJ6l80a4BzJOonUOUmwUeXXSTjN73kHQyEmBZetmDjSaZt/H22sL9fT7iHKtTrfkSUArEZhUkKYSTF4 X-Bogosity: Ham, tests=bogofilter, spamicity=0.015274, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Kairui Song Setting backing device is done before ZRAM initialization. If we set the backing device, then remove the ZRAM module without initializing the device, the backing device reference will be leaked and the device will be hold forever. Fix this by always reset the ZRAM fully on rmmod or reset store. Fixes: 013bf95a83ec ("zram: add interface to specif backing device") Reported-by: Desheng Wu Suggested-by: Sergey Senozhatsky Signed-off-by: Kairui Song Cc: stable@vger.kernel.org --- drivers/block/zram/zram_drv.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index e86cc3d2f4d2..45df5eeabc5e 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1444,12 +1444,16 @@ static void zram_meta_free(struct zram *zram, u64 disksize) size_t num_pages = disksize >> PAGE_SHIFT; size_t index; + if (!zram->table) + return; + /* Free all pages that are still in this zram device */ for (index = 0; index < num_pages; index++) zram_free_page(zram, index); zs_destroy_pool(zram->mem_pool); vfree(zram->table); + zram->table = NULL; } static bool zram_meta_alloc(struct zram *zram, u64 disksize) @@ -2326,11 +2330,6 @@ static void zram_reset_device(struct zram *zram) zram->limit_pages = 0; - if (!init_done(zram)) { - up_write(&zram->init_lock); - return; - } - set_capacity_and_notify(zram->disk, 0); part_stat_set_all(zram->disk->part0, 0);