Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6029251rwb; Mon, 14 Nov 2022 13:08:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf6um9EXUOG+ktWCNanTzM9BekD4A6SV3CIcLO9zwzW6WYDRULQtF0GxiUqV3uupGf0SLtoM X-Received: by 2002:a05:6402:d51:b0:462:3340:758f with SMTP id ec17-20020a0564020d5100b004623340758fmr13031532edb.37.1668460130902; Mon, 14 Nov 2022 13:08:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668460130; cv=none; d=google.com; s=arc-20160816; b=C/UOE7favPhhCiiULhnw+gBLfSgrQC5PiPoHLl7kIHYU7G3yLdJgl+witQSfHTP7mv aMa+p1N6HVF+sPYsaNbYo8U3TY+tvd9l1DG3zP9hlddr0s0asQIQNDl/iaOiOFiepwAx PpbIaCae1ym8PbW2JNwqCYwR2yaFV9be30bf1BhoLTZXLPdrhKVgqWHQVTrRQQlD2oEw O6YnBIoqBj0/ubw/MondWdUUixzOcbap/UggVw7H+Cx6i8DexO5hNVXfNlVUU0u3xxxJ ej4ocpwXeOIIQwWFpc8Q1RK4WU4fx3Y7YNrb/wQIjwgw67Hke2+qrf1o4b32qePxp9u+ orPQ== 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 :feedback-id:message-id:subject:from:to:dkim-signature:date; bh=svjeS0KSKiKaa8XQ3/EP+LqmTKTFzWL6J01aoUmFJgQ=; b=Z4lPmxt+XSbsbFu+LapAG8LNl/z835Z1NpI9D9smFWP/OGFGXU9WJ220zwIV141UWg UDW4vqQAEU7W/jElRLbYTCwVv77gV74Ifxa3OhiLJC1lW0cae8XZXcSfG7gZimYGYVH/ 0TMJLmGn0U14jFzdde1cLQjxvQZwy1nOPyX/ZbiB3Ol5fBuQkpTGyWmAYLbLLq2UUgBV y78ptO+b0vsm2/75ErEElo8OmOEq4KDT/iQUN7ppaB/Azopp1FObqbI0WcOhGy5lDBir W/pzMxtQunVhmwpRBFABE+pq1a19rxzhvu2cBOYyBcwsNpgcesceEcG8/wgkMtOtaHwy YunA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=RDEwWDxX; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v8-20020aa7cd48000000b00461a32e0e38si7721347edw.306.2022.11.14.13.08.28; Mon, 14 Nov 2022 13:08:50 -0800 (PST) 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=@protonmail.com header.s=protonmail3 header.b=RDEwWDxX; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237266AbiKNTyk (ORCPT + 88 others); Mon, 14 Nov 2022 14:54:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235911AbiKNTyi (ORCPT ); Mon, 14 Nov 2022 14:54:38 -0500 Received: from mail-0201.mail-europe.com (mail-0201.mail-europe.com [51.77.79.158]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 846F5271B for ; Mon, 14 Nov 2022 11:54:37 -0800 (PST) Date: Mon, 14 Nov 2022 19:54:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1668455673; x=1668714873; bh=svjeS0KSKiKaa8XQ3/EP+LqmTKTFzWL6J01aoUmFJgQ=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=RDEwWDxXj8v6CobY6tGsKiEqldkDCO/9FxGEbr3OhZJYlj0YallYth2LMsQhqIw45 9GdEj4PpK7wbtbHIcgWaG0R+hYaXA0LcRWdY1UzO3kvlBP+i0fug0fjdrUsJECsSJz bukhPb0c3YyJorrazNCiY91Q6114uagSxHEpDHl0CX6TkzBY5+9cFZhr2h/7FM/vDy /oxlmCP0+djYLCOIkj3U0s+kD+duuKG41vy253kh5mC/J0ByTY3KGKt+rpr4Vqf4fJ 3vpMwow0ArWpI36RpO9pkXIh/xvB8Rjv46LseA3KSJZ82VUgxCyU2ekho4xyBeE383 ug8EEcsVRQ2/A== To: linux-kernel@vger.kernel.org, Thomas Gleixner , John Stultz From: =?utf-8?Q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v2] timerqueue: use rb_entry_safe() in timerqueue_getnext() Message-ID: <20221114195421.342929-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS 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 When `timerqueue_getnext()` is called on an empty timer queue, it will use `rb_entry()` on a NULL pointer, which is invalid. Fix that by using `rb_entry_safe()` which handles NULL pointers. This has not caused any issues so far because the offset of the `rb_node` member in `timerqueue_node` is 0, so `rb_entry()` is essentially a no-op. Fixes: 511885d7061e ("lib/timerqueue: Rely on rbtree semantics for next tim= er") Signed-off-by: Barnab=C3=A1s P=C5=91cze --- changes in v2: - reword commit message --- include/linux/timerqueue.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/timerqueue.h b/include/linux/timerqueue.h index 93884086f392..adc80e29168e 100644 --- a/include/linux/timerqueue.h +++ b/include/linux/timerqueue.h @@ -35,7 +35,7 @@ struct timerqueue_node *timerqueue_getnext(struct timerqu= eue_head *head) { =09struct rb_node *leftmost =3D rb_first_cached(&head->rb_root); -=09return rb_entry(leftmost, struct timerqueue_node, node); +=09return rb_entry_safe(leftmost, struct timerqueue_node, node); } static inline void timerqueue_init(struct timerqueue_node *node) -- 2.38.1