Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2303169iof; Wed, 8 Jun 2022 01:57:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy92bTJaeOLIZhLT5iveDlJnBssZvk9Ws2Rtctj9/KVvdfjRfws+JEVuKNI9xoyA30/ifUO X-Received: by 2002:a63:884a:0:b0:3fc:bcef:5685 with SMTP id l71-20020a63884a000000b003fcbcef5685mr29283959pgd.349.1654678641518; Wed, 08 Jun 2022 01:57:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654678641; cv=none; d=google.com; s=arc-20160816; b=GzsqGUVl1jOZI7xUwItiqqHe55lplnaD2ivQe3SzAnm0K/SQQohPFTPZ4CVZIc+OdP VJwxCvnhLpfVSDwrqk+Ic3BvDYD/m701NQUMfqbOb4fsWmpmWzaPfMwkrZ18EaZeXARW RfHx/6bdodB6fDIoQp5TIJF1su4cFBWL9RZtGEXWdsjCzMT6hV3KHReY5XrEGyp7hV0N XCw6yX97iL4+noVhJ4v65WG3drTLexljiiQyNWxI/SJYVtQanhIPcXFGtD2pJaf2jdTA 3k+0kTd8YpDK5ZkbNlGwqgCaMACPUIVC0BsBRjW4f/BLTSz0RIFm3EUlMvi7/nb+Jwde WxxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=6d//xLMZewJABqjk9QF8SiDnR9wNTei67iI7EwN0sFs=; b=s36Icvn9SqUddpSSRQMsQUpTcnIysI9+gdExPywZ0nZhtbSnhM/cZD1oyIbFqx5KSo 6XjCs7dimkaU0HT4BaoMbfTTNxCw4dneBvcM79TFKy5M6jcN9hB/va3ePn57O+MAz1g9 bPwqNAW529N5BDpqRlXCEJ2gO/1jg3Phs/HSATPAepcZxAIj/3RtZWnQwQfW686b1T2S 3DkSclVsX2aISyxUWVJuDTN+sdzF5re5Sxno0uicksyvWIgQwykwEqtZBTKLCarN/JCN 8CcbYYlWMpwZUJsRuuFz/XxcyPsm0YcTIYH+NE7839q7bUTIlWxPITvnyUBB9sck6NEn qG+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d184-20020a6368c1000000b003fd023128f8si22014184pgc.851.2022.06.08.01.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 01:57:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2F0A5404361; Wed, 8 Jun 2022 01:20:15 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230281AbiFHIRB (ORCPT + 99 others); Wed, 8 Jun 2022 04:17:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231759AbiFHIP3 (ORCPT ); Wed, 8 Jun 2022 04:15:29 -0400 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C4EE362ED0; Wed, 8 Jun 2022 00:44:15 -0700 (PDT) Received: by mail-ed1-f49.google.com with SMTP id c2so25884369edf.5; Wed, 08 Jun 2022 00:44:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=6d//xLMZewJABqjk9QF8SiDnR9wNTei67iI7EwN0sFs=; b=5y6MAFkU9tZWqfaonH4bxUiQSBZKYz+tFXGcwlfbMjDOzmoED7bkcM+cCKm4hXmKDD 26CF7DouWcjj+BQPedtKXDGAK4wiqX8EtMTrBBMysbV+g286zsM/AebFEub9zfmGgrED 6vxnMtGT5xIonC+VpnuUs8FfWs7xhKkhXSGDZeN6eMkjSzro0W53qCCfMkbmnASwkL58 K8lEQpyJTLxqHRHAqsjxY+nTwvoKvDE37XMjr4PWXAV0kLWYx8pbgOwUOcK39t3msauv 8TtMIZmNkATN/GuHaAtxU3LSSfTINYI1Zhn1/Y8qjIrHKFSl6QH36rJA3MAe9RytKUPz GfaQ== X-Gm-Message-State: AOAM532q/YyDCVPNNrj0LJOncuIoJkjRv8J1gUG8ea+hojsQY+NNLfr2 mFZj9UY8WmfV1ZflbvRIleU= X-Received: by 2002:a05:6402:40d4:b0:430:97a9:fa53 with SMTP id z20-20020a05640240d400b0043097a9fa53mr24886638edb.158.1654674254041; Wed, 08 Jun 2022 00:44:14 -0700 (PDT) Received: from ?IPV6:2a0b:e7c0:0:107::49? ([2a0b:e7c0:0:107::49]) by smtp.gmail.com with ESMTPSA id s4-20020a1709067b8400b006f3ef214ddfsm7067295ejo.69.2022.06.08.00.44.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Jun 2022 00:44:13 -0700 (PDT) Message-ID: <5a1a600a-5a1f-d93b-e854-2586c412e505@kernel.org> Date: Wed, 8 Jun 2022 09:44:12 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH 33/36] tty/vt: consolemap: change refcount only if needed in con_do_clear_unimap() Content-Language: en-US To: =?UTF-8?Q?Ilpo_J=c3=a4rvinen?= Cc: Greg Kroah-Hartman , linux-serial , LKML References: <20220607104946.18710-1-jslaby@suse.cz> <20220607104946.18710-33-jslaby@suse.cz> From: Jiri Slaby In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On 07. 06. 22, 17:31, Ilpo Järvinen wrote: > On Tue, 7 Jun 2022, Jiri Slaby wrote: > >> con_do_clear_unimap() currently decreases and increases refcount of old >> dictionary in a back and forth fashion. This makes the code really hard >> to follow. Decrease the refcount only if everything went well and we >> really allocated a new one and decoupled from the old dictionary. >> >> I sincerelly hope I did not make a mistake in this (ill) logic. >> >> Signed-off-by: Jiri Slaby > > It seems fine: > > Reviewed-by: Ilpo Järvinen > > One unrelated comment below for additional cleanup opportunity. > >> --- >> drivers/tty/vt/consolemap.c | 13 +++++++------ >> 1 file changed, 7 insertions(+), 6 deletions(-) >> >> diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c >> index 01b7e49f1f91..4d8efe74315c 100644 >> --- a/drivers/tty/vt/consolemap.c >> +++ b/drivers/tty/vt/consolemap.c >> @@ -535,22 +535,23 @@ static int con_do_clear_unimap(struct vc_data *vc) >> { >> struct uni_pagedict *old = *vc->vc_uni_pagedir_loc; >> >> - if (!old || --old->refcount) { >> + if (!old || old->refcount > 1) { >> struct uni_pagedict *new = kzalloc(sizeof(*new), GFP_KERNEL); >> - if (!new) { >> - if (old) >> - old->refcount++; >> + if (!new) >> return -ENOMEM; >> - } >> + >> new->refcount = 1; >> *vc->vc_uni_pagedir_loc = new; >> + >> + if (old) >> + old->refcount--; >> } else { >> if (old == dflt) >> dflt = NULL; > > This seems unnecessary as con_release_unimap() already does it. Good point -- the code is real mess... Now, the mess is more apparent, at least ;). I will create a separate patch for this. thanks, -- js suse labs