From patchwork Wed Aug 23 16:02:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 136723 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a7d1:0:b0:3f2:4152:657d with SMTP id p17csp701278vqm; Wed, 23 Aug 2023 13:21:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE1K1s8rzSPq6uqYf31cDapHCUmiO50caXDuH/N00YrSYxWtQsJTaEs2P9Rwvn2W203eRT2 X-Received: by 2002:aa7:db47:0:b0:523:18db:e3ab with SMTP id n7-20020aa7db47000000b0052318dbe3abmr9421935edt.39.1692822074395; Wed, 23 Aug 2023 13:21:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692822074; cv=none; d=google.com; s=arc-20160816; b=dy4KemGCqMKx3Shtg1dLI9xRU/yulv0w/hcFWwmm8QBPdkvlVEdAaGonncdP8v0tUB Sap0fv/ulmETh/CgdII9jPSu5hhTYtZ6Muleopy3n4RCmOTN90DsgcXhzK97XgrYk/qH fxYIyFrlY3Xi+xSq5SxZ73A6joRoWwwkCXrnvsEmKyri69tRZeeBDfy+nXrt/6wmO6FB jv9UqmNqmT/y4nzH6htYZQDQGBmd6JkyjJPZrPg3g4/gdKKZHjQfFEjv1EkaEu3rfd0z Qff85hgepLQ4MtEsPoZpG0TGhPm+VGubre0WKZhDpTWVGSrzsPLgzvrsR063ngzMMPqM yQfQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sN+nxCYag6UTfc3rspE3t+tCy7YWalh5Xl9myqFkZXk=; fh=/3+8DBUoOgFqi8oZMBQNje9qrGOWaxwDXR2aVoiip+4=; b=KhK8XvvN0A7qF46x1zrCtoxG4bFbvyWnacLGiF2Ft56qWfQB9IFOWPexP4VBYZ+tld CybkUiDrkgBM4M2SKCCCaQbz4rWiZzs0asq5n1uGIln4/EfmnRbnctiAJgCW3JBW6wIC 7h/2o+ILBT/nYIkbwg3jiOIHJcdolstShEmQ9OnDhEX44+M/0Hy66nebsh/g5J4Eksm6 sENKoUc44VrXmbjWsqYPiZNndktR63AQf2P9a09Gy0TtgNzKI0uI/L+zVUZletxtjo7P KciEPryzN70Y+RzAiV3mr3ho3IEddt2DsDdbrYCZ15yXR2S0/58CMDIgYrVnhE0zvMS6 7z6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CaJBfxIu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v22-20020aa7d9d6000000b0052a0875ef70si6054996eds.438.2023.08.23.13.20.48; Wed, 23 Aug 2023 13:21:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CaJBfxIu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237395AbjHWQDG (ORCPT + 99 others); Wed, 23 Aug 2023 12:03:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233326AbjHWQDE (ORCPT ); Wed, 23 Aug 2023 12:03:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26CE9184 for ; Wed, 23 Aug 2023 09:03:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B358B64C73 for ; Wed, 23 Aug 2023 16:03:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EBB7C433C9; Wed, 23 Aug 2023 16:02:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692806582; bh=B0H4dHXC38o+d2MdOwkbIjWWV7KKjINlqQcF0ZM4v/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CaJBfxIuHDGUQfR82jwImtDeEYwRnuK598N3YnBro4YqghUOgGDC0vQYXNDkE/vwZ EtsEENYUkTsXjXCwDiPjR3e2Z/vw9fGcxwnTOJ+KxxjC7O6dnXcgwGD9VHnJaMQDSB nBnyFwRrYBM7sis6zcmoS8qpK5V+3Dvw9Mi7JIfxxDffZJlJPaDbXSrcIT+7WtGhYJ rPzO6ViFue+yyoRNYMUZp6xMlSKCfll2IXEWSzR7W8iCqFGu043C1cY8pXoBEo0WYK SnuA8Y9Sz697KGy/MLYIZUSOCrQL8nPNW6K39l8dzUw51GPlHwRSwh0p9jNRdUoylB 6dDmv+iYdAw8g== From: Miguel Ojeda To: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor Cc: Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: [PATCH 1/2] rust: arc: add explicit `drop()` around `Box::from_raw()` Date: Wed, 23 Aug 2023 18:02:42 +0200 Message-ID: <20230823160244.188033-2-ojeda@kernel.org> In-Reply-To: <20230823160244.188033-1-ojeda@kernel.org> References: <20230823160244.188033-1-ojeda@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775052599528597881 X-GMAIL-MSGID: 1775052599528597881 `Box::from_raw()` is `#[must_use]`, which means the result cannot go unused. In Rust 1.71.0, this was not detected because the block expression swallows the diagnostic [1]: unsafe { Box::from_raw(self.ptr.as_ptr()) }; It would have been detected, however, if the line had been instead: unsafe { Box::from_raw(self.ptr.as_ptr()); } i.e. the semicolon being inside the `unsafe` block, rather than outside. In Rust 1.72.0, the compiler started warning about this [2], so without this patch we will get: error: unused return value of `alloc::boxed::Box::::from_raw` that must be used --> rust/kernel/sync/arc.rs:302:22 | 302 | unsafe { Box::from_raw(self.ptr.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: call `drop(Box::from_raw(ptr))` if you intend to drop the `Box` = note: `-D unused-must-use` implied by `-D warnings` help: use `let _ = ...` to ignore the resulting value | 302 | unsafe { let _ = Box::from_raw(self.ptr.as_ptr()); }; | +++++++ + Thus add an add an explicit `drop()` as the `#[must_use]`'s annotation suggests (instead of the more general help line). Link: https://github.com/rust-lang/rust/issues/104253 [1] Link: https://github.com/rust-lang/rust/pull/112529 [2] Signed-off-by: Miguel Ojeda --- rust/kernel/sync/arc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs index 172f563976a9..4c14d540a581 100644 --- a/rust/kernel/sync/arc.rs +++ b/rust/kernel/sync/arc.rs @@ -299,7 +299,7 @@ fn drop(&mut self) { // The count reached zero, we must free the memory. // // SAFETY: The pointer was initialised from the result of `Box::leak`. - unsafe { Box::from_raw(self.ptr.as_ptr()) }; + unsafe { drop(Box::from_raw(self.ptr.as_ptr())) }; } } }