From patchwork Mon Feb 12 17:01:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 200033 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp167883dyb; Mon, 12 Feb 2024 13:06:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW/RDeoiaIOLq/lA5S53Cb1M3Z7ieyOQgnYJo7Bn3NsjTEkqxWbuwfgFMimgVqxb8IL31HA3lzQj5s921X800BRjoMaIA== X-Google-Smtp-Source: AGHT+IF4ElqX0RphEV3nrSrmKUUMtpGmY1tO+YbRKkXy9b6VwAy8gsavn8jm1xUunI9IPC3aRnQY X-Received: by 2002:ac2:44ab:0:b0:511:87ee:297b with SMTP id c11-20020ac244ab000000b0051187ee297bmr4220719lfm.53.1707771990807; Mon, 12 Feb 2024 13:06:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707771990; cv=pass; d=google.com; s=arc-20160816; b=nVKPP/8dssN2KxloirMAF+6Fw/JTAngydZ5AUGwYdZeiHv5fVi5WfaKw/foE69tS6B Tbnx62B1hIx61eiLUhG0mgUqskK3oWOksglzgXmKSwllk8WlTgC5S1oBEyWR4BkVpO2W T1H6TGQsdm7bdx/wEyThFZMTL60cHvMMLTird9/BSUgYCo3NDY5HtM3rxl41z5VLZmL9 Mv4orkk0mZwtXyA39AmjEQp2G+l77UnOsuffzrmCL4Dcy8Q7jol7zxCMguy4YKGRwPou QJ8BvtRlMR8wgPBU2zAIOx7c9mNeX5AGu8Pq8dPRjgpYPoT6V4RMxM/2vkqnfD9la30M vzpQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=CrrL9zswLR7T+/jMsTSJ1HgKN74bXvsZvsqSVGYxPx0=; fh=Je8GYmrgtI9JGGHTJbNaEkFa2xxZoiECpzF7sgUeGFc=; b=LQyZLgZy8f3diNk2IjuKUgf6URxVBby8J4bJV7EMHa1SUcYY3wgIay/cFeZcZZTnui 3rO5RkP5zdIDrGn2XMef4hsGO9IzH7vlsD6fkMK5f/C9N84EMNhDvkn+yltE7cfDXxqb 1uX98Z4ngw6ygcEjN6/Bi5ddauByNBvPDZCFCJWVEL6xW0XOWhM3IDoaAPkuYElgSqzC ilIbbnyEAT0BR4KOlM80Ke8VpIIhDKsA31IqNkoMqgrHZzQZQ0A6O9U9AY8cojroT5YQ w7lXBA9x6YIqV0vtrzdpW08QAnLinrlsx3ZnPzkXyFOylqWQ0Un+YnmddN3Vup58f/ED nayA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LynqWGE8; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-62044-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62044-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCVxAilXr5pHhgci2jaBT89wx35fRiEL4YgSB8wh7FO5EtvvsqZu8cWgG1wrhvXR8ERYZeRSkBepaMYLBJm/4WljL7n86A== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g26-20020a1709063b1a00b00a3cea51e75bsi239751ejf.788.2024.02.12.13.06.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 13:06:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62044-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LynqWGE8; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-62044-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62044-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 4FBB91F286DC for ; Mon, 12 Feb 2024 17:08:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 42854481AD; Mon, 12 Feb 2024 17:04:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="LynqWGE8" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 320323FE22; Mon, 12 Feb 2024 17:04:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757491; cv=none; b=jq9dp7Qt92Po8mQk8FqgWD78dkEer0WtsgPZxIjwHACfS8tjcGkY2vgJba59xMtPV4lX6qXA/fJwEal17yKLhZUJk73dSo89R49qgzmf/3+ORcgP3OUZv3bjuQkIK72V4//LAe0hMzc0nPWqZIozmON61oqP2K1rOhuD9rmGcBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757491; c=relaxed/simple; bh=LvC0jNLSvlISq+pfX0tunOut+CloWPeckMMVxbBHVes=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V3rgEtMKZuVG/l5tR9dhdb1uuJ1DH+cASQn/oUGg4/uL1mAQ8Ii0HUanVAAFe279TkNjOlBHAKvY+D+uZ2+TzNCS3R2BqBMA9ma9OmELGB2YLM69Jq4x2HMvkQgvu9QTcYPs8KeQN6+F+h2XBk+ksewdIzF5FYuyGoyb6nszi2g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=LynqWGE8; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707757491; x=1739293491; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LvC0jNLSvlISq+pfX0tunOut+CloWPeckMMVxbBHVes=; b=LynqWGE8tHLRz/g63tYhFPvqI082pSK9xAdvxatg9Rpw86Cpf/Rz5+Ng 75UUJhizNmy4peZTrH38RDKpuf/emAp+SU9YJCBiN3QA3z0/o/whpNBmK zhrMUHvgd59yf3EoEyQ3sg07xbv6SaIbWoVcUOFhnArn9jfb4Fi9u+iEw HNijb5arUW0Gs8PW5XsmfxKnXYgqIW7vevqruwHSLTOoKcnRWi7gmT7Sv /QYkGczvfRbrjE1gApJRx2evkaUNZ2fB7BXlPYiQOZgCPFRbz2xInuEJw lFMRY6jiuUOvjs1mIPgrlgnXPnR1fxQvfKef1H+29xrmOlNTf//7DUQMR A==; X-IronPort-AV: E=McAfee;i="6600,9927,10982"; a="19153187" X-IronPort-AV: E=Sophos;i="6.06,264,1705392000"; d="scan'208";a="19153187" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 09:04:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10982"; a="935116809" X-IronPort-AV: E=Sophos;i="6.06,264,1705392000"; d="scan'208";a="935116809" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 09:04:43 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id A9268138; Mon, 12 Feb 2024 19:04:42 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andy Shevchenko , Geert Uytterhoeven , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Robin van der Gracht , Paul Burton Subject: [PATCH v2 03/15] auxdisplay: linedisp: Use unique number for id Date: Mon, 12 Feb 2024 19:01:36 +0200 Message-ID: <20240212170423.2860895-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20240212170423.2860895-1-andriy.shevchenko@linux.intel.com> References: <20240212170423.2860895-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790728722818555155 X-GMAIL-MSGID: 1790728722818555155 The absence of decrementation of linedisp_id is incorrect in two ways, i.e. it may cause: - an ID exhaustion - (and if the above is addressed) a duplicate id number may be allocated next time a device is added Replace above mentioned approach by using IDA framework. Signed-off-by: Andy Shevchenko Reviewed-by: Geert Uytterhoeven --- drivers/auxdisplay/line-display.c | 13 ++++++++++--- drivers/auxdisplay/line-display.h | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/auxdisplay/line-display.c b/drivers/auxdisplay/line-display.c index 310e9bfb41ae..c4dbb13293d1 100644 --- a/drivers/auxdisplay/line-display.c +++ b/drivers/auxdisplay/line-display.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -188,11 +189,14 @@ static struct attribute *linedisp_attrs[] = { }; ATTRIBUTE_GROUPS(linedisp); +static DEFINE_IDA(linedisp_id); + static void linedisp_release(struct device *dev) { struct linedisp *linedisp = container_of(dev, struct linedisp, dev); kfree(linedisp->message); + ida_free(&linedisp_id, linedisp->id); } static const struct device_type linedisp_type = { @@ -214,7 +218,6 @@ int linedisp_register(struct linedisp *linedisp, struct device *parent, unsigned int num_chars, char *buf, void (*update)(struct linedisp *linedisp)) { - static atomic_t linedisp_id = ATOMIC_INIT(-1); int err; memset(linedisp, 0, sizeof(*linedisp)); @@ -225,9 +228,13 @@ int linedisp_register(struct linedisp *linedisp, struct device *parent, linedisp->num_chars = num_chars; linedisp->scroll_rate = DEFAULT_SCROLL_RATE; + err = ida_alloc(&linedisp_id, GFP_KERNEL); + if (err < 0) + return err; + linedisp->id = err; + device_initialize(&linedisp->dev); - dev_set_name(&linedisp->dev, "linedisp.%lu", - (unsigned long)atomic_inc_return(&linedisp_id)); + dev_set_name(&linedisp->dev, "linedisp.%u", linedisp->id); /* initialise a timer for scrolling the message */ timer_setup(&linedisp->timer, linedisp_scroll, 0); diff --git a/drivers/auxdisplay/line-display.h b/drivers/auxdisplay/line-display.h index 0f5891d34c48..1fbe57fdc4cb 100644 --- a/drivers/auxdisplay/line-display.h +++ b/drivers/auxdisplay/line-display.h @@ -14,6 +14,7 @@ /** * struct linedisp - character line display private data structure * @dev: the line display device + * @id: instance id of this display * @timer: timer used to implement scrolling * @update: function called to update the display * @buf: pointer to the buffer for the string currently displayed @@ -25,6 +26,7 @@ */ struct linedisp { struct device dev; + unsigned int id; struct timer_list timer; void (*update)(struct linedisp *linedisp); char *buf;