Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751813AbdHACPL (ORCPT ); Mon, 31 Jul 2017 22:15:11 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:36422 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751784AbdHACPK (ORCPT ); Mon, 31 Jul 2017 22:15:10 -0400 From: Yafang Shao To: mingo@redhat.com, peterz@infradead.org Cc: linux-kernel@vger.kernel.org, laoar.shao@gmail.com Subject: [PATCH] sched: fix NULL pointer issue in pick_next_entity() Date: Tue, 1 Aug 2017 18:01:56 +0800 Message-Id: <1501581716-8608-1-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1152 Lines: 32 When we select CFQ as the scheduler, in function pick_next_task_fair it will pass NULL as the 2nd argument to pick_next_entity: pick_next_entity(cfs_rq, NULL); And once __pick_first_entity() is called, it could return NULL as well. So in function pick_next_entity(), the local variable 'left' and 'curr' could both be NULL, then this will cause NULL pointer issue. In order to fix this issue, we just need return NULL under the condition that both 'left' and 'curr' are NULL, meaning that no entity available. Signed-off-by: Yafang Shao --- kernel/sched/fair.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index c95880e..e64c359 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3903,6 +3903,8 @@ static void clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se) struct sched_entity *left = __pick_first_entity(cfs_rq); struct sched_entity *se; + if (!left && !curr) + return NULL; /* * If curr is set we have to see if its left of the leftmost entity * still in the tree, provided there was anything in the tree at all. -- 1.8.3.1