From patchwork Tue Jun 25 16:41:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13711616 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5748173324 for ; Tue, 25 Jun 2024 16:42:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719333725; cv=none; b=BuI+En7pnlBA2HL8Muk1rGGxb0gftaVWOsRhXGHVd9kU3RFkFicON51w7cxhXlrleJsCnv1aB2JNv9rv7XY7lj8YAaOoAYnCGk51dPgv5fIu++9LB/YYSqYQw0+fAtmrhe8Q5+s4zhUWY0xF/JRX2n/o8NAh0wndkIUXO/l4zFo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719333725; c=relaxed/simple; bh=1+sQ9K8OPFNJBbvDYPpjxVlqqc6+2sxYzZRnuyh8aAg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rgutUOR+76ptVbmpAu+seuik6xJO9ilt6fewtS42KNZu5DoSmZkbxr8UFWPJITRMUsrOUuz8QlLG9ookg23BPjUuR9mxdVuxxIriLzqMjpTdo1zH5XmCFlKHlCUnGqpdG01zK0nC2zEMgNzBEhGVwhCmN3S2YvVD3HaspjsX+nM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=h3QgcVxp; arc=none smtp.client-ip=209.85.210.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="h3QgcVxp" Received: by mail-ot1-f46.google.com with SMTP id 46e09a7af769-700cc388839so341867a34.0 for ; Tue, 25 Jun 2024 09:42:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719333723; x=1719938523; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=psw16ttjtER33796PhTeXerRJsahRiSzkaP+NSpJRiU=; b=h3QgcVxpn5OA/6QZrBsQCK+zJYDoANaOtqtsHeU+TVjp6OYMOWNVwgElFAnWzmSpph nObR5tvqoOZMamBT41zmskAeDsnGsPPGGarA5LAg9L0Zj/r9Cnm7OQ2WjJekv5qtsxqX jwNdmzhmPawWrQ3abC2aHI+4jemf0un4culXGBxZGjJrr1jBUfC0j+Y8ytK7bJadIJq5 sh3tJhCWtwEmlN0gUgXvBOEuorT+2w3gbQySZugXNN+P6HqlHW/5Fb4FKtRVDdYVYstu UU+tK+0MYD8nv3dp4izRJ113+cvs6zdCa0Ig/sownLTdL8ctYnLtUTL8NoPceJvCh5cl wXYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719333723; x=1719938523; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=psw16ttjtER33796PhTeXerRJsahRiSzkaP+NSpJRiU=; b=Va5+zvz/L/7cdlbF4zV2wP5PxNa778rF5UkMbc0WgUmMLlaMfUTgaUnpbmN2AmH59Q JS1I2xaWJxhBVmAfrYol64Rjsf2iTustZrGDb9q+nuVHmw3mTB+dTAJqtMlBzyKHybc/ 9HM1eOmP3ChaxGenQzqS3aDPNhbuR1m8jbrfvxrrtbSB+6YEHZ8t33hbkjp2qsQTE34T xyFmVrOlDoKoJAQqt+dUgLsL93QyeofUJ0wUqmkQGWaTOnymPm/iMJvV8/BuRQ9s757g OInw5ZZU1JEzl41Pa6EyVo8jZiDIK1bhr8PSfVD4Wma6KFaHS8sPn55e7eLU7GD035gf pi+Q== X-Gm-Message-State: AOJu0YxKsoAVZcY6Afwy5+8H6IQxhFCGq2lxJZoMElFk2C+bSecltzZt D3Ie8kbjDXwkzR2oOfxq7HpLiL06hmU2n3Tm3sta9BLMTaIkF5g9luyqiQ== X-Google-Smtp-Source: AGHT+IG6gsmhKtJt4IcWoOO6A6yFyOhwlsJsb/tB2OwQGIJadT73/VkvMxYTX1tnU5YvHENFepe20A== X-Received: by 2002:a05:6830:16c1:b0:6fb:8411:2f16 with SMTP id 46e09a7af769-700afa4b5abmr8717409a34.31.1719333722739; Tue, 25 Jun 2024 09:42:02 -0700 (PDT) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5c1d55dc2dcsm1884844eaf.27.2024.06.25.09.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jun 2024 09:42:02 -0700 (PDT) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH v2 03/14] qmi: Move service_handle allocation to service_family Date: Tue, 25 Jun 2024 11:41:39 -0500 Message-ID: <20240625164158.1170937-3-denkenz@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240625164158.1170937-1-denkenz@gmail.com> References: <20240625164158.1170937-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A unique service handle identifiers is allocated every time a new service is created. The unique identifier is generated by qmi_device and is monotonically increasing. qmi_device has now been completely refactored out of the public API and only remains as an implementation detail. It is desirable to remove it and transform it into a QMI transport abstraction. As a first step, remove service handle id allocation from struct qmi_device and move it into struct service_family instead. As a consequence, ensure that when a request is canceled, compare both the service_handle and the service_family group_id since both are required to identify that a request belongs to a particular service. As a side effect, lightweight service handles are now not able to accidentally cancel (by tid) requests they do not own. --- drivers/qmimodem/qmi.c | 65 +++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c index 238039d4add7..828f62584ea0 100644 --- a/drivers/qmimodem/qmi.c +++ b/drivers/qmimodem/qmi.c @@ -90,7 +90,6 @@ struct qmi_device { struct l_queue *req_queue; struct l_queue *service_queue; unsigned int next_group_id; /* Matches requests with services */ - unsigned int next_service_handle; uint16_t next_service_tid; struct l_queue *service_infos; struct l_hashmap *family_list; @@ -129,6 +128,7 @@ struct service_family { unsigned int group_id; uint8_t client_id; uint16_t next_notify_id; + unsigned int next_service_handle; struct l_queue *notify_list; }; @@ -1140,14 +1140,13 @@ static struct service_family *service_family_create(struct qmi_device *device, static struct qmi_service *service_create(struct service_family *family) { - struct qmi_device *device = family->device; struct qmi_service *service; - if (device->next_service_handle == 0) /* 0 is reserved for control */ - device->next_service_handle = 1; + if (family->next_service_handle == 0) /* 0 is reserved for control */ + family->next_service_handle = 1; service = l_new(struct qmi_service, 1); - service->handle = device->next_service_handle++; + service->handle = family->next_service_handle++; service->family = service_family_ref(family); return service; @@ -2349,11 +2348,32 @@ uint16_t qmi_service_send(struct qmi_service *service, return __service_request_submit(device, service, &sreq->super); } +struct request_lookup { + uint16_t tid; + unsigned int service_handle; + unsigned int group_id; +}; + +static bool __request_compare_for_cancel(const void *a, const void *b) +{ + const struct qmi_request *req = a; + const struct request_lookup *lookup = b; + + if (req->service_handle != lookup->service_handle) + return false; + + if (req->group_id != lookup->group_id) + return false; + + return req->tid == lookup->tid; +} + bool qmi_service_cancel(struct qmi_service *service, uint16_t id) { struct qmi_device *device; struct qmi_request *req; struct service_family *family; + struct request_lookup lookup = { .tid = id }; if (!service || !id) return false; @@ -2367,12 +2387,15 @@ bool qmi_service_cancel(struct qmi_service *service, uint16_t id) if (!device) return false; - req = l_queue_remove_if(device->req_queue, __request_compare, - L_UINT_TO_PTR(id)); + lookup.group_id = family->group_id; + lookup.service_handle = service->handle; + + req = l_queue_remove_if(device->req_queue, __request_compare_for_cancel, + &lookup); if (!req) { req = l_queue_remove_if(device->service_queue, - __request_compare, - L_UINT_TO_PTR(id)); + __request_compare_for_cancel, + &lookup); if (!req) return false; } @@ -2385,9 +2408,12 @@ bool qmi_service_cancel(struct qmi_service *service, uint16_t id) static bool remove_req_if_match(void *data, void *user_data) { struct qmi_request *req = data; - unsigned int service_handle = L_PTR_TO_UINT(user_data); + struct request_lookup *lookup = user_data; - if (req->service_handle != service_handle) + if (req->service_handle != lookup->service_handle) + return false; + + if (req->group_id != lookup->group_id) return false; __request_free(req); @@ -2395,10 +2421,15 @@ static bool remove_req_if_match(void *data, void *user_data) return true; } -static void remove_client(struct l_queue *queue, unsigned int service_handle) +static void remove_client(struct l_queue *queue, unsigned int group_id, + unsigned int service_handle) { - l_queue_foreach_remove(queue, remove_req_if_match, - L_UINT_TO_PTR(service_handle)); + struct request_lookup lookup = { + .group_id = group_id, + .service_handle = service_handle, + }; + + l_queue_foreach_remove(queue, remove_req_if_match, &lookup); } static bool qmi_service_cancel_all(struct qmi_service *service) @@ -2415,8 +2446,10 @@ static bool qmi_service_cancel_all(struct qmi_service *service) if (!device) return false; - remove_client(device->req_queue, service->handle); - remove_client(device->service_queue, service->handle); + remove_client(device->req_queue, + service->family->group_id, service->handle); + remove_client(device->service_queue, + service->family->group_id, service->handle); return true; }