From patchwork Wed Dec 4 18:02:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13894152 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 48E7AE7716D for ; Wed, 4 Dec 2024 18:02:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BF5836B0083; Wed, 4 Dec 2024 13:02:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BA5DE6B0088; Wed, 4 Dec 2024 13:02:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A1E946B0089; Wed, 4 Dec 2024 13:02:38 -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 7FE5B6B0083 for ; Wed, 4 Dec 2024 13:02:38 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E37151C7DD8 for ; Wed, 4 Dec 2024 18:02:37 +0000 (UTC) X-FDA: 82858046502.16.1C13B16 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by imf18.hostedemail.com (Postfix) with ESMTP id 41D751C0027 for ; Wed, 4 Dec 2024 18:02:29 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bCwgLDSg; spf=pass (imf18.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.215.169 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=1733335349; 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=7V53GFvkYgl3GGn7NQiYaXdsYVvKlvlq6z/L7Et1GuE=; b=6Y9zh7QItIJRvYOLZq1R9Vuv4YiG7/n7fUVGmk2qF0IQXLm8D9hsQttHkLxejlahHIJ3s0 IOlcBwGT1p8OCq66IEsL3y5og/UtkWC7KoDuMgbKZ5AabVJ4EjtouRBlc0yCwIvLSfZjDA Et5kwkgRGDz81BpAeCPqEjutsWr6CSM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733335349; a=rsa-sha256; cv=none; b=4VjFQn1XFGZwGuIQ7JLHRHuPZSrU5deZZO2YiDVZ+p+Gn1hVJIGv8YjZLmGJTeuPEoMCZe m4DLO27K71GLJMi2IfJlU1ecp0YthPibhBUSo+nVA2Nq83w9L4nOub3WpUFCmvCcUGdkuM 6/lVQWd2kBVgjYOgng+e1gsQv3fABCY= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bCwgLDSg; spf=pass (imf18.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-7fd10cd5b1aso52858a12.2 for ; Wed, 04 Dec 2024 10:02:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733335354; x=1733940154; 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=7V53GFvkYgl3GGn7NQiYaXdsYVvKlvlq6z/L7Et1GuE=; b=bCwgLDSgo85SCymms0Z/5ND8KgekAjugWKW9/ryorbpawH3MAbW/yZ6OodRVrf+Hni 52X4ffh1N/PwHK69ol2VxE20fk5BcJBLMVLCqDVnnW9pgctzjecLVNWWTN4dMDHVMLw6 AkbWn1DW3nrg/UKQgXrR7aTjEPw5JC9th6OsXUL3+WV8nhER4D4bzyGtVvtLuDsVWIfs Za5Wo82X803DKMP7qP3iURjfrvWs1yUz7q8h1TI3lH5C122tMQ8RzE81OuuQYq/b7xdj 2vVZrfKghYo/LAXKL8hp9C/Go+nJnYWksKYoH7ecfQf3/MlBkY4e6RMtFkBCkVso6tfF TQuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733335354; x=1733940154; 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=7V53GFvkYgl3GGn7NQiYaXdsYVvKlvlq6z/L7Et1GuE=; b=JaGr1gLNFpCiBUebamTVmUS5Ly/JE7Bi/4v6cGhOKkmcsyhL1oL7k+xUS8R6lkJC5q 5uyYHeZhSuM+spPxEermw/tVZRrjM5YpNIP5um+PxBijlHBp9vsuKqD6O6hl+RnxKeWs k/aJ6uCUSqLP8/Awv7zvs0Pgd8ClFOZ+qVzbACmjjvhavg+1bk7imvKI38KYFZ+xJd3c u30LETz5aql8ryG37mgi8Pp4TfgvDTjYZWbfHY9qBLqAsNmd1nOocEw5eXCCwr5p0EhC uBQ7sW7MGWWlezigedOVMIszlPJQd861H99yXQ5FJuhk9b8KkFOhZxGZKeF5J6/QzFOY KD8A== X-Gm-Message-State: AOJu0YzBUXDvRKcwnLTmPs4Kl4sXuYtYl7j7MfIV2O78ac+Ws/gsN7QQ bUHfKPV+yGGWLamNjWaDcKLEQDjpz2P4ccro89jBozsHsCafv6Raxi/AL19k4/c= X-Gm-Gg: ASbGncu/GhC5zKn/iX0jhdP5UEKoIahvDsGjFScXKPz70nxwrq03PeGC7Azp4RZiJue OnFeYlkd++aNb1GIzJ36Swr9LbgLWwgCpg4EoGsZXs09vLfIs8zMDnv6taYk8jWxtOfdOF5bl1h GAdQDEUDTgmkZK0rZgPeA5mSj+OjQu+TvFgpRcO7jphCfeDJqgYsjEBZd8RW4Q3v0JToTZsSfjU NF0lfVrAD72VxTYbk7tHUypHGVFgDebKeYnPCYEwtaZPoSghCa6iu12Io/MMlbP/nBIgtU= X-Google-Smtp-Source: AGHT+IGfGswqHPS+sVCVBRyy6YYEmMkEmFcHRdeKF8fO4AaC3KytnZpu1qaS+nFgVW1qeM0JFQPoRQ== X-Received: by 2002:a05:6a21:330b:b0:1e0:d837:c929 with SMTP id adf61e73a8af0-1e16bdd32cemr8217439637.9.1733335353855; Wed, 04 Dec 2024 10:02:33 -0800 (PST) Received: from KASONG-MC4.tencent.com ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7258947b48fsm2064736b3a.47.2024.12.04.10.02.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 04 Dec 2024 10:02:33 -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 1/2] zram: refuse to use zero sized block device as backing device Date: Thu, 5 Dec 2024 02:02:23 +0800 Message-ID: <20241204180224.31069-2-ryncsn@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241204180224.31069-1-ryncsn@gmail.com> References: <20241204180224.31069-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 41D751C0027 X-Stat-Signature: 6x8w671tdq8fajfs8ktp6734n55wwg4g X-Rspam-User: X-HE-Tag: 1733335349-959104 X-HE-Meta: U2FsdGVkX19sS8g5B0/ag/A5pimSNUlQahCJNMT/KrTOYnjuHJ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wkMnNxfhW1Qx27aP32GY++tFQBwYZpq/28bUcM+Ho3O6/2Z6oVJSurWw9EsB7KO1yMACYJMW7tU/BfXOUPmgsycQ8/DpLGsS82GZHiC6HfU1uomMnplm4I1CtnZ+oam1THcEFTskmGs/MihZq+DRaoMBgTnM5QPtwI4jxuLbbzE29Jl1TiPS0kaQE1YWLtENw3Sca4FKdKzQ+t36CTgYpUx/Tr7J5klRJUJqRtfc7dLRaxeQXosilbusWOxDaK7SrU1/+fuADeE1kp45CmUgSX3Z3DawV8Y1g7Lx3PgmhJ1KBCCLW3t5xUY9j0xWCRqZSlMgM2/Kp8MOWqOneWqTEKoChNtwVsspUpmIXhdff8fzNjJfXVU93FdPUYI1EV2nTwT6RI68CPa9vcs0m50lc1FkIpTJG6ml+CP4RbEE5ZS4thxXktm33ho3jRDf7/i6BA48btfr3rLfuvcQfQ/mk8rCdBGH9Uy3C1bMseyKSGGF2JaOxUS5AFYQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000006, 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 Cc: stable@vger.kernel.org Reviewed-by: Sergey Senozhatsky --- 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 0ca6d55c9917..dd48df5b97c8 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 Wed Dec 4 18:02:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13894153 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 45891E7716D for ; Wed, 4 Dec 2024 18:02:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5B3A6B0088; Wed, 4 Dec 2024 13:02:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B0B026B0089; Wed, 4 Dec 2024 13:02:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 983836B008A; Wed, 4 Dec 2024 13:02:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 75FD06B0088 for ; Wed, 4 Dec 2024 13:02:41 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EA522C1042 for ; Wed, 4 Dec 2024 18:02:40 +0000 (UTC) X-FDA: 82858046250.27.7119D68 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf26.hostedemail.com (Postfix) with ESMTP id C510D140020 for ; Wed, 4 Dec 2024 18:02:27 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=luj4egeU; spf=pass (imf26.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.176 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=1733335345; a=rsa-sha256; cv=none; b=oMgsIV0pL+ExKnnQoxXCN38vbOmNxG7XggDL92JMvZnxigiK+vsmqWK53X77ycjgpi8g3f KUogthTEQNZ+fWPrjqsJpezzQ/F7aRYb+K7KrueW8dPE5DbyNgbgbCze0VV/7pL5FZs8+L kXVCkMVGDBshNmCxZOxYEJmueJELCu0= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=luj4egeU; spf=pass (imf26.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.176 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=1733335345; 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=bAlGt/tiVuSRFhJS9Rkw9mOuskNJthnKTcKF5ulNOvw=; b=EEpRT16BevAV+95EiHfMy0glI3ebtKIhhHfcHPpP5iZMl1pC4hxPe7GdPGi3dgALCnsO/H 8Q4Q6dM/tStA++l9tNmgPH72v/2GSE1DedIBTuMTzLKgKjjWbkWViregU/wHeV0M0cfybr XgpeBFyFa6ClVtV15Dr/3+3L2VnabcA= Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-724d57a9f7cso78386b3a.3 for ; Wed, 04 Dec 2024 10:02:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733335357; x=1733940157; 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=bAlGt/tiVuSRFhJS9Rkw9mOuskNJthnKTcKF5ulNOvw=; b=luj4egeUjK8TIatlBK3SrmMV3Fslr5Dds6szqoBo5Nb9pN+uzUErycibMXWOf/fq1U YIgOGHnovieEZLhqMa9lO/1wv/kVy+Dj/XMCEK3aIQAkqHT6mirg6ORDn8+x/Ke3x3qz cAOv0he2Yflvw5+MVrfxe4XhrqDrsLKIOB+m6HSgYyk6vWNN90jvjG2SXrTlGXiCkRen HtDBROZ8+sI5XLpxP1GY+pcFY6YPEZuhFntzlxmy5AeODvbGay46M5Y/fpPfcu7GvgjG mjzvcnDD/OU25yCBVpZaDJOGckvuZIX+cHFLtQU+/WkzmjtVe57z0RLQCGfWZVO873Qm 0pbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733335357; x=1733940157; 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=bAlGt/tiVuSRFhJS9Rkw9mOuskNJthnKTcKF5ulNOvw=; b=AbtxT3UvbFyXeqe80xH8xKw9wPzHoK2UmeRiqlWh6LMogAu2uErej5aYPjRt0yCzVm CA6qeF5KmCr1xB2TbwNSFHEaxdtn3+n9XprTm6q9fisuApePzwYBTBfcKyrYLOHv7IXW 71CvC7bnwAreKoVd/HbvJa+Oj3xgNvpP3AbwfzSka74vMkbYDn9qtCAH9VrFouUSaEeI DXkLUjq3mBw/YqipppTZ26FRIq0ZI218wCQljcLJFuSZsm+Y7b5EN3+DapvGLKepbnie veoe9foZanXV1nN5y0REOOGwB9oe8UZy19VoQBFRcBfhsN2psL/vMfWt6tJJ2VyApsCV PPgQ== X-Gm-Message-State: AOJu0YwQqylSTGWu1yeAu5VFU3r8jGzAchT0rDGQg5k+3SdTEBubjX2B 6oje54CZjAfuzkQkYpjVWl3EZeOJgiOuJzokCoByOjj9IOEquhvG/RQSeGYpVTU= X-Gm-Gg: ASbGncu6G6zHqrjffjHDfB0B30Y02MCuyf/cJY3j8Eym08VhZ1Klkj3IV42XpM7zpvK MYtztv30TlDxRY0g2iSFR8iGTlVEC3sKYJureJbTTkMOkFW8UMl4Fuc00aaEwwYl4i3F3+jg99m /z1KDIA0+qDcFB5bMqDMY54/h26Y0+l21ClgcnOVrBt5XHDbd0YLxNWDM3FvIZl48VGHq8aiMb6 JLE+WjLf/nWYLx8FwFKeDTy31FrleevSHxxA1n6CbwZykb7iM6sk4c+D+ZG/Fq0qF2pi/0= X-Google-Smtp-Source: AGHT+IHeql1iWXSfpkc9alhz3TOTPqPIWd0paC+yeqbkwcITYB2dvWkcwBYhP1UiZzR3SpjSJkLP+g== X-Received: by 2002:a05:6a00:3c8c:b0:71e:f4:dbc with SMTP id d2e1a72fcca58-7257fcced2cmr9725349b3a.25.1733335357173; Wed, 04 Dec 2024 10:02:37 -0800 (PST) Received: from KASONG-MC4.tencent.com ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7258947b48fsm2064736b3a.47.2024.12.04.10.02.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 04 Dec 2024 10:02:36 -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 2/2] zram: fix uninitialized ZRAM not releasing backing device Date: Thu, 5 Dec 2024 02:02:24 +0800 Message-ID: <20241204180224.31069-3-ryncsn@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241204180224.31069-1-ryncsn@gmail.com> References: <20241204180224.31069-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Queue-Id: C510D140020 X-Stat-Signature: 8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vT6xnZCk5ea7A5Qd6dQHFI85nogKMmTjsXaR6XbPmjrJ8qdEuPV4MIcH1VhellDYf0LGZIe6dYx1+uhR/yL7+eatqwv7596VnfdDuzwb/ZBybcfUsm1oFqUW0/sNb+o6VepGEMrmLl4+EfCf6MytHVUmx9f9R4FUeJuz3z2Y23AvzwMJp5bVQF8lVGFEExGzyfa2rlY68crVXPeyDt/go97PPYU2eEfhupHl3zDQAVakYFJFbW4rSthN9pX3of+vRaR072qJkIDMzVZWOX5ozP3Xs4j9OnBSyi21/fgZyHNMCQ9QbGyjsrSnwC91zR8tOyTZJ/ytPR3GHjfQ615cesUJ1ZJ77UZhRexqs4rdOEjvOTP35qq7Ix+hgkB74J1KSBNq3Hmg9Yz0QTT83LVzu4m1WBCHfstrlMQpDr0patWMu9DC+/fogsNUeS/muwoHVxM2OyCl8mQp97u5Nw0AZ1MSXXAK2mYOpy33HSQJlrG5ldBrB8T55OaiWT0TX7Tsamdg5/i2M+yIDbb2A2d9mAH4ks4fcMLLHOrnBZ76sJTowVzvnLSqUfx+kUSlAmOi4SRyRR//JFoIqiLSO99rCl3GGbp9zXmNQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.006955, 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 check and release the backing device when resetting or removing ZRAM. Fixes: 013bf95a83ec ("zram: add interface to specif backing device") Reported-by: Desheng Wu Signed-off-by: Kairui Song Cc: stable@vger.kernel.org --- drivers/block/zram/zram_drv.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index dd48df5b97c8..dfe9a994e437 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -2335,6 +2335,9 @@ static void zram_reset_device(struct zram *zram) zram->limit_pages = 0; if (!init_done(zram)) { + /* Backing device could be set before ZRAM initialization. */ + reset_bdev(zram); + up_write(&zram->init_lock); return; }