Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp460533lql; Mon, 11 Mar 2024 07:48:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVedFNOSQxb88XFPo8cWpJuW+5fMVhV/Wj2anWGeKsh4isVJmv7ndjC/hEbWjEybakcVvHpYta3xOOUq1DFH92H/uM6TfJ6YESSh/JSpg== X-Google-Smtp-Source: AGHT+IGaaW4ZT2PeN5NGAB1eXi4NESZKflTKl88M/jemCAD7aOTsuGHVwwbkgURRWLvEGmkkgXdw X-Received: by 2002:a05:6a20:8048:b0:1a1:44bb:da3f with SMTP id f8-20020a056a20804800b001a144bbda3fmr6177541pza.53.1710168521123; Mon, 11 Mar 2024 07:48:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710168521; cv=pass; d=google.com; s=arc-20160816; b=kuMsFrh+ZccxIDjMR/SSKh7F8VZHETffKniALvI3DPNRoHhg0HwJFZgdDi1KOgW9fx OAuRdM4CfybYxaJWHKT+MLCZbK3TkK+f9/xGuRew5/kYY1QVcLnxLMVhpIFkFkN1Ilu+ 036xheD8hzXl6HPVDqw2QF15H1/4xvaX3zif62CVPEt0V4iBspZr4p7ZgnLsRRVAMYK8 xXrLTzY4VMpLsX7m0PiRGZllPfcWHk+fBt7W1UDmUa5vjQKW4mpvTd0TUGqo2+VRpUDd nxt+VQCOYS8Zo4bgsScN4TIOanLPiZvei4UiCsXKhbKhw5F1MkwOlS+BQzB4k213JxPY hkqw== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=HE2HlRBk0CBdOeSYlTEx7Aew3iPhhdjEpCgk9BsO9gQ=; fh=VK5/4T7lm1YjxlHAn1l+9Z5feMmMkYZmz7v4+K6kiHM=; b=eHaXvEk+Q8im8q1oo2MzU8TlEmuy3HeOEtCIdjdITVmcPt3vdGDAM7d+9rHWtN0azY +hIzIxYrcQiXg7VQRc15uOvQ8z7NdbRNwk1j5VvjarC/6yc2SDNPwcHY+2wZnsHeHAr4 lrvy3pyFCw+gu4XmsCTfjJ4mAHhHoMEWu7itUCfQVOyQSiCqTGAE1watvxfpkRALjeFW rvQGT/2NqGyXEeXkav3num5pdjgDY6NJYl2DTvQ2+UA338XCYsjrUsUUzBfy4/KkbAKN kfzvViKdvmlduJWppssxqIDfrSBgGLXEFHTEx9A8Emx+ZqbF8UJxIJLOFxtUMeX1v1JT l/FQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=ME9I65hw; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-98988-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98988-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u16-20020a170902a61000b001dcd51578d7si4774454plq.14.2024.03.11.07.48.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 07:48:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-98988-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=ME9I65hw; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-98988-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98988-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A4C1D282C52 for ; Mon, 11 Mar 2024 14:47:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D205840877; Mon, 11 Mar 2024 14:47:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="ME9I65hw" Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 3CAE41E4A4; Mon, 11 Mar 2024 14:47:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710168455; cv=none; b=JuTunmowsRBjYBOx94XHhbhF2zpS2g1QG905O+71kGfo77Nbb0c+DqLVWNMJkNrFkWyPc9aT3QTvU2ARUjKLDjeH1iwOq7mWnKimiCZGRrkYbv+WPykU7PgdUE011kCczrROZtxm48NqoSNp/aJACyKBQ1GIwKc+HUSbWbjRiS0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710168455; c=relaxed/simple; bh=mQXbuf91ZGqc0/FW7JST9LvaYVs66Pk9EWKyVUxqaOk=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=rt9EQGaTJbWLxvHZxD+CeKePsJ7AKUADiiv+r5qNA8UmJ1SbhMxkfPVrK/O2x1PsSzUO+FmQkIHtmzK8ujddBzvtnOX6O4d5NvIxNbUHd2beCL58JP6R5YPYtzD3hydLlVzcjmAb5V5s1SjltjYRhDlIvxw8vKjAjUtk3KcrrJ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=ME9I65hw; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 9181120004; Mon, 11 Mar 2024 14:47:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1710168451; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=HE2HlRBk0CBdOeSYlTEx7Aew3iPhhdjEpCgk9BsO9gQ=; b=ME9I65hwjLbO2WQWF9QhXRqs2ZIq/wUMSUiT6DcXHioA0Vn52PY+Kv5C4MEagpn0CBOzzN kEoDSOSWs23+4zjGB2edNFf+68spN5UiP0hyOamcAfDgULY60OoZWJSUcdFoU/xgrLSUg5 xkwk5mJYoRsuwKvOd239R2mwZ/spHcUHrvz0M7I9YeE1RMgyVd+MmdWFaOS8kMi6sojsLw TzQB1Tdw9vhmtsJsINlCo5XiQ+GTPlJDC4qvigITzqTEQAEb5VjWPDfZjgfEMsfmpwcKYI reGN4+MzM2fAy2TqoKtCHUKaaoBlrgYoNdPYpVdSOjkV9QEENRM750PGgLVZKw== From: Kory Maincent To: Jakub Kicinski , Simon Horman , Przemek Kitszel , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: thomas.petazzoni@bootlin.com, Richard Cochran Subject: [PATCH v4 net-next] ptp: Move from simple ida to xarray Date: Mon, 11 Mar 2024 15:47:29 +0100 Message-Id: <20240311144730.1239594-1-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: kory.maincent@bootlin.com Move from simple ida to xarray for storing and loading the ptp_clock pointer. This prepares support for future hardware timestamp selection by being able to link the ptp clock index to its pointer. Signed-off-by: Kory Maincent Reviewed-by: Przemek Kitszel --- Change in v2: - Update an err value missing. Change in v3: - Refactor err management. Change in v4: - Remove useless 0-init of err in ptp_clock_register. - Use the right xarray header. --- drivers/ptp/ptp_clock.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c index 3aaf1a3430c5..dd024bb33426 100644 --- a/drivers/ptp/ptp_clock.c +++ b/drivers/ptp/ptp_clock.c @@ -4,7 +4,6 @@ * * Copyright (C) 2010 OMICRON electronics GmbH */ -#include #include #include #include @@ -16,6 +15,7 @@ #include #include #include +#include #include #include "ptp_private.h" @@ -31,7 +31,7 @@ struct class *ptp_class; static dev_t ptp_devt; -static DEFINE_IDA(ptp_clocks_map); +static DEFINE_XARRAY_ALLOC(ptp_clocks_map); /* time stamp event queue operations */ @@ -201,7 +201,7 @@ static void ptp_clock_release(struct device *dev) bitmap_free(tsevq->mask); kfree(tsevq); debugfs_remove(ptp->debugfs_root); - ida_free(&ptp_clocks_map, ptp->index); + xa_erase(&ptp_clocks_map, ptp->index); kfree(ptp); } @@ -233,7 +233,7 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, { struct ptp_clock *ptp; struct timestamp_event_queue *queue = NULL; - int err = 0, index, major = MAJOR(ptp_devt); + int err, index, major = MAJOR(ptp_devt); char debugfsname[16]; size_t size; @@ -241,16 +241,16 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, return ERR_PTR(-EINVAL); /* Initialize a clock structure. */ - err = -ENOMEM; ptp = kzalloc(sizeof(struct ptp_clock), GFP_KERNEL); - if (ptp == NULL) + if (!ptp) { + err = -ENOMEM; goto no_memory; + } - index = ida_alloc_max(&ptp_clocks_map, MINORMASK, GFP_KERNEL); - if (index < 0) { - err = index; + err = xa_alloc(&ptp_clocks_map, &index, ptp, xa_limit_31b, + GFP_KERNEL); + if (err) goto no_slot; - } ptp->clock.ops = ptp_clock_ops; ptp->info = info; @@ -258,13 +258,17 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, ptp->index = index; INIT_LIST_HEAD(&ptp->tsevqs); queue = kzalloc(sizeof(*queue), GFP_KERNEL); - if (!queue) + if (!queue) { + err = -ENOMEM; goto no_memory_queue; + } list_add_tail(&queue->qlist, &ptp->tsevqs); spin_lock_init(&ptp->tsevqs_lock); queue->mask = bitmap_alloc(PTP_MAX_CHANNELS, GFP_KERNEL); - if (!queue->mask) + if (!queue->mask) { + err = -ENOMEM; goto no_memory_bitmap; + } bitmap_set(queue->mask, 0, PTP_MAX_CHANNELS); spin_lock_init(&queue->lock); mutex_init(&ptp->pincfg_mux); @@ -378,7 +382,7 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, list_del(&queue->qlist); kfree(queue); no_memory_queue: - ida_free(&ptp_clocks_map, index); + xa_erase(&ptp_clocks_map, index); no_slot: kfree(ptp); no_memory: @@ -511,7 +515,7 @@ static void __exit ptp_exit(void) { class_destroy(ptp_class); unregister_chrdev_region(ptp_devt, MINORMASK + 1); - ida_destroy(&ptp_clocks_map); + xa_destroy(&ptp_clocks_map); } static int __init ptp_init(void) -- 2.25.1