Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1094911pxb; Fri, 3 Sep 2021 23:34:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwM6n9hmE595mduqC0ARv9BhAhlNlkS0gkQBpNzHuWiLyyQIXzU5kuuF6/sMiyAU1slGbUy X-Received: by 2002:a17:907:212e:: with SMTP id qo14mr2714263ejb.501.1630737262982; Fri, 03 Sep 2021 23:34:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630737262; cv=none; d=google.com; s=arc-20160816; b=tz6P0D3T0ISFlkp2X+aCYKPM/V2OG0QFzhYBuwyKscVr6/9yLv09++zcZ8jsfyMlZg MgFydkHv6wm12p2TcoOf4O0Vt5Nk5NzRptRa9ggWvYASLZcjowzq73x/sNE+DwNhYYNO PXugMKuiTMosDaf+ThUR5bk3MGwp3q9tFVBdk9eaj7clDtrnL1lF/9qdwWtbKf90EWRu wL9ZHuxyKyuxVBlwWjL+0eDc6XZiHmmP4RI0eevhmrzzHDTRUB3tV5ozzZLiWOGBOcAq wyQJDWZ7VgOW2F3sepiD9dhIjnH16nTNQ7pizqyzwGaceaA9saJZxakePD1lfQtvfDQM TRKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=fHCK1ZecJYrv9lqXvAKK4uDVpfNOEid1hERe7Vyz3Vc=; b=K9xDdttX6ZSkFwsKkycySHcLzLDZGbldw5u6oXB6AZzp73bCTtg3KM27cpKREU+Cei BPc4Y9qybc1vxi7KHARyMgHA08eO+Vuc3PojWnxqZhghLf3U1TzDimO/R+fcbCcmMaNS 23ReN7Kfm1OSc0Abqlv3WVX69VJ/7ZajJKCuadTpqndx/y3hl/tNkW1bEqu2auJKzRyb RjAbvyaSdflwnk5/2ghjHl/FFw6rbhLQjEyTRLZ012gu1klE0EKrBkN7SBvix1AxX29N AhuJa/BeUpecMUYbI11ZeUrx9J8/fPbwvNGV0+IJHA30f4oOV9pYPfEpejLD7Mx96t1j BfIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="d/MIbhKD"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g18si1836754eds.512.2021.09.03.23.33.59; Fri, 03 Sep 2021 23:34:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="d/MIbhKD"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242799AbhIDGdP (ORCPT + 99 others); Sat, 4 Sep 2021 02:33:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:43888 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237120AbhIDGdN (ORCPT ); Sat, 4 Sep 2021 02:33:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 86B086054E; Sat, 4 Sep 2021 06:32:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1630737132; bh=ZPixSAawQQqPuj5uTZ0OeL9TEp8tDj5LW5EOE0Smepc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=d/MIbhKDeLeoLRvVQQfgo9+2BdYnw8uaZ2zrYxmKYhibNiR8YwL9k1hUtLOrhSwx5 bXqqacppUMaTthPvrFxtBiLNj1Rb4sN0lA7ZcS+KOqvfc7rtX50JFHHkNWZast4wF9 Jrr9smC8vjzWfotZEC1Wid5NuxHXwKthyFA0BQGg= Date: Sat, 4 Sep 2021 08:32:09 +0200 From: Greg Kroah-Hartman To: Jiazi Li Cc: Arnd Bergmann , Jiazi Li , linux-kernel@vger.kernel.org Subject: Re: [PATCH] char: misc: init list head only when needed Message-ID: References: <853e8529c18c4a71c36b49f9598961fbc3f39682.1628921932.git.lijiazi@xiaomi.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <853e8529c18c4a71c36b49f9598961fbc3f39682.1628921932.git.lijiazi@xiaomi.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 16, 2021 at 06:12:32PM +0800, Jiazi Li wrote: > If a module successfully registers a misc device. > Then, due to some bugs, use same address register misc device > again, init list head will corrupt misc_list, resulting in oops > when using misc_list. Then fix those bugs that try to register the misc device more than once? Does that happen in any in-kernel drivers or is this just a failure of external drivers that are not submitted to the kernel tree? > In this scenario, do not init list head, if registration is > successful, init list head is also not required. > > Signed-off-by: Jiazi Li > --- > drivers/char/misc.c | 19 ++++++++++++++----- > 1 file changed, 14 insertions(+), 5 deletions(-) > > diff --git a/drivers/char/misc.c b/drivers/char/misc.c > index ca5141e..2451640 100644 > --- a/drivers/char/misc.c > +++ b/drivers/char/misc.c > @@ -176,7 +176,6 @@ int misc_register(struct miscdevice *misc) > int err = 0; > bool is_dynamic = (misc->minor == MISC_DYNAMIC_MINOR); > > - INIT_LIST_HEAD(&misc->list); > > mutex_lock(&misc_mtx); > > @@ -185,7 +184,7 @@ int misc_register(struct miscdevice *misc) > > if (i >= DYNAMIC_MINORS) { > err = -EBUSY; > - goto out; > + goto err2; > } > misc->minor = DYNAMIC_MINORS - i - 1; > set_bit(i, misc_minors); > @@ -195,7 +194,13 @@ int misc_register(struct miscdevice *misc) > list_for_each_entry(c, &misc_list, list) { > if (c->minor == misc->minor) { > err = -EBUSY; > - goto out; > + /* > + * if module use same address double register, > + * init list will corrupt misc_list I do not understand the text here at all, sorry. thanks, greg k-h