From patchwork Tue Feb 20 23:25:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Schrock X-Patchwork-Id: 13564759 Received: from mx0a-003ede02.pphosted.com (mx0a-003ede02.pphosted.com [205.220.169.153]) (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 E23CD78688 for ; Tue, 20 Feb 2024 23:27:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.169.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708471627; cv=none; b=pcWcNhrd71gh4BN2pfWGh//IfHfDQipGjK+2dgJc94MQAdIcPqom8DVkbbe9Q0wYVlrdX9ciOLaxl0lxK9ZpESI2P8kA9foNpsRr5Cb1/hbcZ42MxaTSE2JQRE4tj96l2yMVWp1uDeW0daY3h9f8cA8L9eicbAXBnu1UlMrspLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708471627; c=relaxed/simple; bh=xZ0nJ012E2Af7YyZrZod/hF8TXF0e860VpAC9FStiHc=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=U5YZ4+3ne3GMPVbozYAeHRFCXiLvFhP/ReN9k/BPZNW7NBvG7DNALuen4A/7WhiREhwPhUA/dnqQ8BUBqNqLw9BEb13yA8HBoMXDpI6pqXUHdKYFSlHJywurro1vEHf8/8u+qXNd8Gqqsbx/dMxXOk1rBibTFgfRhv4R1CDzXYc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=getcruise.com; spf=pass smtp.mailfrom=getcruise.com; dkim=pass (2048-bit key) header.d=getcruise.com header.i=@getcruise.com header.b=PV+F/TBt; dkim=pass (2048-bit key) header.d=getcruise.com header.i=@getcruise.com header.b=SgO0RNix; arc=none smtp.client-ip=205.220.169.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=getcruise.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=getcruise.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=getcruise.com header.i=@getcruise.com header.b="PV+F/TBt"; dkim=pass (2048-bit key) header.d=getcruise.com header.i=@getcruise.com header.b="SgO0RNix" Received: from pps.filterd (m0286617.ppops.net [127.0.0.1]) by mx0b-003ede02.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41KMkme4009509 for ; Tue, 20 Feb 2024 15:26:59 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=getcruise.com; h=from:to:cc:subject:date:message-id:mime-version:content-type; s=ppemail; bh=PaASEMOHXkL/LbDJ3hduVb7VNTajajnC0k/Gq94+vsA=; b=P V+F/TBtgwXyKZVTNr3T6aG4As/FSajSH2W3egRnBCg9dg0M/jgR2BohmhNBFX7eM BAfEmP7sWQ2z/bsw4vhnBgcgwWP+VFdHtRQjtmuQIi66WZbIOYTn1wzcmAoTrQ+O BtHvziNycrUdKXn4zWHHFh8MiGHyX0MIPNyw2TQsbg3IgQO4SpIkDOuaHm1M+zco Pd2fxYPbe2SXVLAq8jefLuFUbSzigE7U2vom8zO7LhYWoU2ls9XTLMzXsRy2poc2 QMekabwIAq8lc2F10NNqa2psPeCpiKJlIhX4Oym1TxSYuGzVxOd5bFgC5xbglKsD ur6qJ4qY7hjxL99qmtCEQ== Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by mx0b-003ede02.pphosted.com (PPS) with ESMTPS id 3wd56481g7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 20 Feb 2024 15:26:59 -0800 (PST) Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-68f992cd47bso12976886d6.3 for ; Tue, 20 Feb 2024 15:26:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=getcruise.com; s=google; t=1708471612; x=1709076412; darn=lists.linux.dev; h=mime-version:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=PaASEMOHXkL/LbDJ3hduVb7VNTajajnC0k/Gq94+vsA=; b=SgO0RNixb88gz2lWgpIFoadACzqboGlG34FNpgPXqR35KnCGnPhPpVqCVaFTmwqK23 b9sYbnDdu7aY4QEZ0n8eLJSTepWrDKupsVo34eig34D8MQ8LEA8fsa7FHnBhl1UE2eX7 G34oBxs1wS3QV3078WKEGOYibxpj5RIrRhmH9K+AH9eDjim9a1o8bR9jepTodyRqsoR+ +x9wSTttdN4wcYLAAmQXi4z42WjJ0M0odsNa7DLDXV+VZjCB71JVehWrIF8AmBki8w3C QUZ/jX/X9Mj9LzfspEQR7/EoxnalVYupUO7VkHVeuV5SJSwtOb3H7L2CggY2WIBhBM6v FjwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708471612; x=1709076412; h=mime-version:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=PaASEMOHXkL/LbDJ3hduVb7VNTajajnC0k/Gq94+vsA=; b=dfeZJarvSDwh+/at3lRUARzIHUbUgJ2jcdtrnTrRtc6xSn8MqSTzvuLAQ2+RYJ2Ys8 Iz0DXLIZrzEnxkxPxMaeXqsp3OxrAQM2WMGu0ZyMilo0brOv/5+iZoSoWAPrplEouCF7 gaEVC20aLsF3eDev0WwfxsTdDBKI+pSerPVln7SZCCgEeVuq6OCCPVhMfqfd/lFkmgrn 39ny55tJ6xSK+Zd1UeXZkKhl7vKwRQ6nHc+UMLmI65K9KQivLEuODkOaffM4xvwmHJPF qvJ5XaZRfUqMPY9iyeZpGrCPq/F+mo9nLOEMqQorYscs73eUA3grGrhfjnppQB7fMW4V bCog== X-Gm-Message-State: AOJu0YxBMUdkcuEys36eIwlGvJ/b9fkI7CQgtvxqnWEjQFhdaXpx2+2c wlNopTIwKL3uc0sz4re5hW9ku25+hlzDY1YobHlunjqL9RXBncjA4Qdw7ILXPraod0SQq8XzivN Tqr2WBakRvQ2SzjuCGbqpormh+uLbiH6YmHjzuU3d77vXuya257yt7OIWAWFoJw7cEkhpVrb1t1 bt1D51MDg/WNvjBe7JnxXon5b3TCEwZxyhwEe8ZxOJKH6ViSU= X-Received: by 2002:a05:6214:2681:b0:68f:9051:5879 with SMTP id gm1-20020a056214268100b0068f90515879mr4206327qvb.21.1708471612542; Tue, 20 Feb 2024 15:26:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IFV2GFYbQcJWm86Hll/JsgnPhKtmlmJBxN+VDbuxtMtzyb0m+VsA1/AXkBKL3kk0XZNkTTX6w== X-Received: by 2002:a05:6214:2681:b0:68f:9051:5879 with SMTP id gm1-20020a056214268100b0068f90515879mr4206303qvb.21.1708471612034; Tue, 20 Feb 2024 15:26:52 -0800 (PST) Received: from localhost.localdomain ([140.177.180.84]) by smtp.gmail.com with ESMTPSA id mb10-20020a056214550a00b0068f85706ecfsm1931983qvb.104.2024.02.20.15.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 15:26:51 -0800 (PST) From: Steve Schrock To: ofono@lists.linux.dev Cc: Steve Schrock Subject: [PATCH 1/4] qmimodem: Use ell new, malloc, and free functions Date: Tue, 20 Feb 2024 23:25:26 +0000 Message-Id: <20240220232529.128477-1-steve.schrock@getcruise.com> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-GUID: goHO_4M3VW4aCy9wydB_LTpwtydVUIu5 X-Proofpoint-ORIG-GUID: goHO_4M3VW4aCy9wydB_LTpwtydVUIu5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-20_06,2024-02-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402200168 --- drivers/qmimodem/qmi.c | 109 +++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 65 deletions(-) diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c index c9c80975..b51df0e7 100644 --- a/drivers/qmimodem/qmi.c +++ b/drivers/qmimodem/qmi.c @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -176,7 +177,7 @@ static struct qmi_request *__request_alloc(uint8_t service, struct qmi_message_hdr *msg; uint16_t headroom; - req = g_new0(struct qmi_request, 1); + req = l_new(struct qmi_request, 1); if (service == QMI_SERVICE_CONTROL) headroom = QMI_CONTROL_HDR_SIZE; @@ -185,7 +186,7 @@ static struct qmi_request *__request_alloc(uint8_t service, req->len = QMI_MUX_HDR_SIZE + headroom + QMI_MESSAGE_HDR_SIZE + length; - req->buf = g_malloc(req->len); + req->buf = l_malloc(req->len); req->client = client; @@ -216,8 +217,8 @@ static void __request_free(gpointer data, gpointer user_data) { struct qmi_request *req = data; - g_free(req->buf); - g_free(req); + l_free(req->buf); + l_free(req); } static gint __request_compare(gconstpointer a, gconstpointer b) @@ -243,7 +244,7 @@ static void __notify_free(gpointer data, gpointer user_data) if (notify->destroy) notify->destroy(notify->user_data); - g_free(notify); + l_free(notify); } static gint __notify_compare(gconstpointer a, gconstpointer b) @@ -677,7 +678,7 @@ static gboolean can_write_data(GIOChannel *channel, GIOCondition cond, else g_queue_push_tail(device->service_queue, req); - g_free(req->buf); + l_free(req->buf); req->buf = NULL; if (g_queue_get_length(device->req_queue) > 0) @@ -954,9 +955,7 @@ struct qmi_device *qmi_device_new(int fd) struct qmi_device *device; long flags; - device = g_try_new0(struct qmi_device, 1); - if (!device) - return NULL; + device = l_new(struct qmi_device, 1); __debug_device(device, "device %p new", device); @@ -967,13 +966,13 @@ struct qmi_device *qmi_device_new(int fd) flags = fcntl(device->fd, F_GETFL, NULL); if (flags < 0) { - g_free(device); + l_free(device); return NULL; } if (!(flags & O_NONBLOCK)) { if (fcntl(device->fd, F_SETFL, flags | O_NONBLOCK) < 0) { - g_free(device); + l_free(device); return NULL; } } @@ -1049,13 +1048,13 @@ void qmi_device_unref(struct qmi_device *device) g_hash_table_destroy(device->service_list); - g_free(device->version_str); - g_free(device->version_list); + l_free(device->version_str); + l_free(device->version_list); if (device->shutting_down) device->destroyed = true; else - g_free(device); + l_free(device); } void qmi_device_set_debug(struct qmi_device *device, @@ -1173,7 +1172,7 @@ static void discover_data_free(gpointer user_data) if (data->destroy) data->destroy(data->user_data); - g_free(data); + l_free(data); } static void discover_callback(uint16_t message, uint16_t length, @@ -1206,9 +1205,7 @@ static void discover_callback(uint16_t message, uint16_t length, if (len < QMI_SERVICE_LIST_SIZE) goto done; - list = g_try_malloc(sizeof(struct qmi_version) * service_list->count); - if (!list) - goto done; + list = l_malloc(sizeof(struct qmi_version) * service_list->count); for (i = 0; i < service_list->count; i++) { uint16_t major = @@ -1317,9 +1314,7 @@ bool qmi_device_discover(struct qmi_device *device, qmi_discover_func_t func, __debug_device(device, "device %p discover", device); - data = g_try_new0(struct discover_data, 1); - if (!data) - return false; + data = l_new(struct discover_data, 1); data->super.destroy = discover_data_free; data->device = device; @@ -1370,7 +1365,7 @@ static void shutdown_destroy(gpointer user_data) device->shutdown_source = 0; if (device->destroyed) - g_free(device); + l_free(device); } static gboolean shutdown_callback(gpointer user_data) @@ -1427,7 +1422,7 @@ static void qmi_device_sync_callback(uint16_t message, uint16_t length, if (data->func) data->func(data->user_data); - g_free(data); + l_free(data); } /* sync will release all previous clients */ @@ -1442,7 +1437,7 @@ bool qmi_device_sync(struct qmi_device *device, __debug_device(device, "Sending sync to reset QMI"); - func_data = g_new0(struct sync_data, 1); + func_data = l_new(struct sync_data, 1); func_data->func = func; func_data->user_data = user_data; @@ -1510,7 +1505,7 @@ static char *get_first_dir_in_directory(char *dir_path) if (dir_entry->d_type == DT_DIR && strcmp(dir_entry->d_name, ".") != 0 && strcmp(dir_entry->d_name, "..") != 0) { - dir_name = g_strdup(dir_entry->d_name); + dir_name = l_strdup(dir_entry->d_name); break; } @@ -1537,10 +1532,10 @@ static char *get_device_interface(struct qmi_device *device) for (i = 0; i < G_N_ELEMENTS(driver_names) && !interface; i++) { gchar *sysfs_path; - sysfs_path = g_strdup_printf("/sys/class/%s/%s/device/net/", + sysfs_path = l_strdup_printf("/sys/class/%s/%s/device/net/", driver_names[i], file_name); interface = get_first_dir_in_directory(sysfs_path); - g_free(sysfs_path); + l_free(sysfs_path); } return interface; @@ -1567,7 +1562,7 @@ enum qmi_device_expected_data_format qmi_device_get_expected_data_format( } /* Build sysfs file path and open it */ - sysfs_path = g_strdup_printf("/sys/class/net/%s/qmi/raw_ip", interface); + sysfs_path = l_strdup_printf("/sys/class/net/%s/qmi/raw_ip", interface); fd = open(sysfs_path, O_RDONLY); if (fd < 0) { @@ -1593,10 +1588,10 @@ done: close(fd); if (sysfs_path) - g_free(sysfs_path); + l_free(sysfs_path); if (interface) - g_free(interface); + l_free(interface); return expected; } @@ -1633,7 +1628,7 @@ bool qmi_device_set_expected_data_format(struct qmi_device *device, } /* Build sysfs file path and open it */ - sysfs_path = g_strdup_printf("/sys/class/net/%s/qmi/raw_ip", interface); + sysfs_path = l_strdup_printf("/sys/class/net/%s/qmi/raw_ip", interface); fd = open(sysfs_path, O_WRONLY); if (fd < 0) { @@ -1654,10 +1649,10 @@ done: close(fd); if (sysfs_path) - g_free(sysfs_path); + l_free(sysfs_path); if (interface) - g_free(interface); + l_free(interface); return res; } @@ -1666,7 +1661,7 @@ struct qmi_param *qmi_param_new(void) { struct qmi_param *param; - param = g_new0(struct qmi_param, 1); + param = l_new(struct qmi_param, 1); if (!param) return NULL; @@ -1678,8 +1673,8 @@ void qmi_param_free(struct qmi_param *param) if (!param) return; - g_free(param->data); - g_free(param); + l_free(param->data); + l_free(param); } bool qmi_param_append(struct qmi_param *param, uint8_t type, @@ -1698,13 +1693,10 @@ bool qmi_param_append(struct qmi_param *param, uint8_t type, return false; if (param->data) - ptr = g_try_realloc(param->data, + ptr = l_realloc(param->data, param->length + QMI_TLV_HDR_SIZE + length); else - ptr = g_try_malloc(QMI_TLV_HDR_SIZE + length); - - if (!ptr) - return false; + ptr = l_malloc(QMI_TLV_HDR_SIZE + length); tlv = ptr + param->length; @@ -1968,7 +1960,7 @@ static void service_create_data_free(gpointer user_data) if (data->destroy) data->destroy(data->user_data); - g_free(data); + l_free(data); } struct service_create_shared_data { @@ -2012,7 +2004,7 @@ static void service_create_shared_pending_reply(struct qmi_device *device, } g_list_free(*shared); - g_free(shared); + l_free(shared); } static gboolean service_create_reply(gpointer user_data) @@ -2067,9 +2059,7 @@ static void service_create_callback(uint16_t message, uint16_t length, if (client_id->service != data->type) goto done; - service = g_try_new0(struct qmi_service, 1); - if (!service) - goto done; + service = l_new(struct qmi_service, 1); service->ref_count = 1; service->device = data->device; @@ -2111,15 +2101,8 @@ static bool service_create(struct qmi_device *device, if (!device->version_list) return false; - shared = g_try_new0(GList *, 1); - if (!shared) - return false; - - data = g_try_new0(struct service_create_data, 1); - if (!data) { - g_free(shared); - return false; - } + shared = l_new(GList *, 1); + data = l_new(struct service_create_data, 1); data->super.destroy = service_create_data_free; data->device = device; @@ -2169,7 +2152,7 @@ static void service_create_shared_data_free(gpointer user_data) if (data->destroy) data->destroy(data->user_data); - g_free(data); + l_free(data); } bool qmi_service_create_shared(struct qmi_device *device, uint16_t type, @@ -2196,9 +2179,7 @@ bool qmi_service_create_shared(struct qmi_device *device, uint16_t type, if (service) { struct service_create_shared_data *data; - data = g_try_new0(struct service_create_shared_data, 1); - if (!data) - return false; + data = l_new(struct service_create_shared_data, 1); data->super.destroy = service_create_shared_data_free; data->device = device; @@ -2243,7 +2224,7 @@ static void service_release_callback(uint16_t message, uint16_t length, if (service->device) service->device->release_users--; - g_free(service); + l_free(service); } struct qmi_service *qmi_service_ref(struct qmi_service *service) @@ -2267,7 +2248,7 @@ void qmi_service_unref(struct qmi_service *service) return; if (!service->device) { - g_free(service); + l_free(service); return; } @@ -2319,7 +2300,7 @@ static void service_send_free(struct service_send_data *data) if (data->destroy) data->destroy(data->user_data); - g_free(data); + l_free(data); } static void service_send_callback(uint16_t message, uint16_t length, @@ -2496,9 +2477,7 @@ uint16_t qmi_service_register(struct qmi_service *service, if (!service || !func) return 0; - notify = g_try_new0(struct qmi_notify, 1); - if (!notify) - return 0; + notify = l_new(struct qmi_notify, 1); if (service->next_notify_id < 1) service->next_notify_id = 1; From patchwork Tue Feb 20 23:25:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Schrock X-Patchwork-Id: 13564760 Received: from mx0a-003ede02.pphosted.com (mx0a-003ede02.pphosted.com [205.220.169.153]) (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 54FDF78688 for ; Tue, 20 Feb 2024 23:27:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.169.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708471630; cv=none; b=RtSzZeYsUtFX3+PbPY3XpRv1F/4kYeRhYikW9SlCgyeNGV+uKnRqv5U95z+hirDdXvQDPljCaCXgzAsEhQEEO97I5u9QaEknobtJ7VbipWY9tK/mUJeeHOJ1cq4nYwYNmIEs49/jT3e8DZs+YR0Svfhl5YnRdSwY2Wz4ol6z3ug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708471630; c=relaxed/simple; bh=Ap1U95Zq3BSYIWTxpXVrgmHvj7EDrJjVR1s/CjLvOGs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=dfK79xPbztQ62wlcFgNXRplFs4lhFpcIq2jCHgZx2bsogBiEtSDQyAtYpvjF4LF+sh+jMyKYuTph21FzMA78iclPOZeb/IwtC6b126g/1km132wV7fdPtYekyOOB28CVdYb48MyTNJHzr7aj4uiGpQvBhOVB6RZcXxHX0SjtrkQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=getcruise.com; spf=pass smtp.mailfrom=getcruise.com; dkim=pass (2048-bit key) header.d=getcruise.com header.i=@getcruise.com header.b=qUE9Qgcd; dkim=pass (2048-bit key) header.d=getcruise.com header.i=@getcruise.com header.b=RCi7OlW6; arc=none smtp.client-ip=205.220.169.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=getcruise.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=getcruise.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=getcruise.com header.i=@getcruise.com header.b="qUE9Qgcd"; dkim=pass (2048-bit key) header.d=getcruise.com header.i=@getcruise.com header.b="RCi7OlW6" Received: from pps.filterd (m0286614.ppops.net [127.0.0.1]) by mx0b-003ede02.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41KMknKV011066 for ; Tue, 20 Feb 2024 15:27:08 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=getcruise.com; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=ppemail; bh=4UqkteEN/KCpYsgQWhJs4P 54uS0qN87qxwf5z1QdjMQ=; b=qUE9Qgcd63+irLhLjXXBv4Iuc1zSHqt0/3yxeL 2XOAcbWLAUWVwoK3KENu1scQ2jBefPv8uBktXIecnKIVpzT5HnDIFqp5xK/+TSyd dgqiELytMERK1Mb9RjAbIooUuG0KYoajOvNMF3JbeizIRnsZ1Z+eTqcFnSbBhIY7 5cXyrIKOA4THrY6z8rPSW8ugfExQlQx6oHkxoBCptHHNhOPd7IioxgrW7DpBmhzi 1dokSs0Sdaz7rOdc4Kih1hxz4JjqhaJ9w8bM3IHpRDKMefeN3Tyn4PbyEvn1A5rW FpleLZk7XpYuNS5H6ZiEL5Yv8X62bq7rqVeZ9rLxQt86tWiw== Received: from mail-vk1-f198.google.com (mail-vk1-f198.google.com [209.85.221.198]) by mx0b-003ede02.pphosted.com (PPS) with ESMTPS id 3wd565g1fp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 20 Feb 2024 15:27:08 -0800 (PST) Received: by mail-vk1-f198.google.com with SMTP id 71dfb90a1353d-4c9bde37500so789597e0c.3 for ; Tue, 20 Feb 2024 15:27:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=getcruise.com; s=google; t=1708471613; x=1709076413; darn=lists.linux.dev; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=4UqkteEN/KCpYsgQWhJs4P54uS0qN87qxwf5z1QdjMQ=; b=RCi7OlW68eq6ZVSD2T/oNbay6fi/yEFsjr9MdcSA08YrVgGgmHzak3ohpeL/H6/FMR Rki0RJLRIAlrOkyM0ZsPfpiai6Yz+cxGPpnXiKbw+2f6p6HcBW2FBTPDhjobrYM29Pgd EJCb+iOGo30oUj4yTClpzecYEEYClKVamGbdSsrkISaoRE44gG7m/7VkGhx+NLCNO62W MFykZJGH7iMbiYHXswAJd5VEqavATph0yHusOuQ5pI4npdelyHLnt2o+mkiyaesbJGr6 Et/1A2hB7Kq+UxgbErDO/2jxr+NZhgARIENS3pM7n/sAWXJ/DWUPI9rvqyHTHlXU1rEV wlAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708471613; x=1709076413; h=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=4UqkteEN/KCpYsgQWhJs4P54uS0qN87qxwf5z1QdjMQ=; b=keIJGWlrKBvyNqzi306YIMstQzwDu9R16OZRR4lAXB7kkaMuDZ+r+vXU5y5ipM73cE Sk3Ld5MZ/LbfbWaBwr5x7VU94KsIh8gbr3u1+ghSlpaUdSo/3QbKWjIfiJKM0q69O+50 oaV3YB8Buq7OJ1HOiJMcSOukkcuh6OlTbYtQ0MPqe3kdgGVR3nTOTCdqb685BL82OdKz /LQ9tSgToCrdTPme+2V0pHUXIbFa8A4abg14M77wBgHFnW5RvtqRtkCGuuQIz1+Gj/De HH1vEqTIwBngozPpFJhuOn2/xygDb3VGcgGWM2cS8T6fuWOJNuTHoYHJxVr7QCxWhOkz XhNA== X-Gm-Message-State: AOJu0Yzu4fvVhfdQf7C8J+v9wODyypQX13+qCtT9ougA4Vhn+Zhn5C9H wpqCDAzt+KLHQwLbODy4HHb5QTZFDXroshOreQke9DOHcJSKv8NH7SbqJ9W/s+0JCUNpO/mXJbs lOS4A2NO/J3UdcZIt3voDF2/G4gKSAPIkir6Z/rrK32VPj9zGWJt1zN9sjIfIg2GOYIFsAdB1yX +dY6R4PElFBuKEVTrmbe6eElvxPh0MCXfywdYpHkvkNjzopZM= X-Received: by 2002:a1f:eb41:0:b0:4c9:9ff9:b334 with SMTP id j62-20020a1feb41000000b004c99ff9b334mr5823877vkh.4.1708471613153; Tue, 20 Feb 2024 15:26:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IH16Jnm2qlCNZNwh1JZeG2MWtD5H4OLrsDqLfkYvPi14jpALOIRD+rmYQz6QINapur9ZDBjPg== X-Received: by 2002:a1f:eb41:0:b0:4c9:9ff9:b334 with SMTP id j62-20020a1feb41000000b004c99ff9b334mr5823866vkh.4.1708471612741; Tue, 20 Feb 2024 15:26:52 -0800 (PST) Received: from localhost.localdomain ([140.177.180.84]) by smtp.gmail.com with ESMTPSA id mb10-20020a056214550a00b0068f85706ecfsm1931983qvb.104.2024.02.20.15.26.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 15:26:52 -0800 (PST) From: Steve Schrock To: ofono@lists.linux.dev Cc: Steve Schrock Subject: [PATCH 2/4] qmimodem: Use l_util_hexdump Date: Tue, 20 Feb 2024 23:25:27 +0000 Message-Id: <20240220232529.128477-2-steve.schrock@getcruise.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240220232529.128477-1-steve.schrock@getcruise.com> References: <20240220232529.128477-1-steve.schrock@getcruise.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-GUID: YtR0QqDmdgMi1-rCwMx08qTaaOgMQ0lI X-Proofpoint-ORIG-GUID: YtR0QqDmdgMi1-rCwMx08qTaaOgMQ0lI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-20_06,2024-02-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 phishscore=0 adultscore=0 spamscore=0 suspectscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402200168 --- drivers/qmimodem/qmi.c | 51 ++++-------------------------------------- 1 file changed, 4 insertions(+), 47 deletions(-) diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c index b51df0e7..b8f019cc 100644 --- a/drivers/qmimodem/qmi.c +++ b/drivers/qmimodem/qmi.c @@ -271,49 +271,6 @@ static gboolean __service_compare_shared(gpointer key, gpointer value, return FALSE; } -static void __hexdump(const char dir, const unsigned char *buf, size_t len, - qmi_debug_func_t function, void *user_data) -{ - static const char hexdigits[] = "0123456789abcdef"; - char str[68]; - size_t i; - - if (!function || !len) - return; - - str[0] = dir; - - for (i = 0; i < len; i++) { - str[((i % 16) * 3) + 1] = ' '; - str[((i % 16) * 3) + 2] = hexdigits[buf[i] >> 4]; - str[((i % 16) * 3) + 3] = hexdigits[buf[i] & 0xf]; - str[(i % 16) + 51] = isprint(buf[i]) ? buf[i] : '.'; - - if ((i + 1) % 16 == 0) { - str[49] = ' '; - str[50] = ' '; - str[67] = '\0'; - function(str, user_data); - str[0] = ' '; - } - } - - if (i % 16 > 0) { - size_t j; - - for (j = (i % 16); j < 16; j++) { - str[(j * 3) + 1] = ' '; - str[(j * 3) + 2] = ' '; - str[(j * 3) + 3] = ' '; - str[j + 51] = ' '; - } - str[49] = ' '; - str[50] = ' '; - str[67] = '\0'; - function(str, user_data); - } -} - static const char *__service_type_to_string(uint8_t type) { switch (type) { @@ -665,8 +622,8 @@ static gboolean can_write_data(GIOChannel *channel, GIOCondition cond, if (bytes_written < 0) return FALSE; - __hexdump('>', req->buf, bytes_written, - device->debug_func, device->debug_data); + l_util_hexdump(false, req->buf, bytes_written, + device->debug_func, device->debug_data); __debug_msg(' ', req->buf, bytes_written, device->debug_func, device->debug_data); @@ -883,8 +840,8 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond, if (bytes_read < 0) return TRUE; - __hexdump('<', buf, bytes_read, - device->debug_func, device->debug_data); + l_util_hexdump(true, buf, bytes_read, + device->debug_func, device->debug_data); offset = 0; From patchwork Tue Feb 20 23:25:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Schrock X-Patchwork-Id: 13564764 Received: from mx0b-003ede02.pphosted.com (mx0b-003ede02.pphosted.com [205.220.181.153]) (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 0D84F40BFD for ; Tue, 20 Feb 2024 23:47:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.181.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708472837; cv=none; b=iSkWLqMvSmmenrY4ZGg1EOXFmDA/Gh/i6ZgK2FwJZmtAw4JoII9z1wdmcOfmb5s3AidIXhBCvzMEFOf/pg4gFm+75XCeGrxX6nWzMk3HsM0TQxtBLChCTEHVofdI08qHdDZtuZLTjVMFAefn2bvA0g5hG5IXOpIopwbnwKqO7vo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708472837; c=relaxed/simple; bh=WYYlEIW1yZxdbzawq8MJU0+gEMLPvQqiadXOnzb4KYE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=k4iRUF0ZzsEopN9QNx/ceI1PpFuhjX3qZEXN/QV1XJATxRaORIG5VwmOHlDhWL48G7QWRcdLGayyTLfbsmHa3eQi/C3fYmkNbDCs4qt6r9gjeXOL0GDihG5XVo+/dX+hrfnRgLcFyT2Hx2DqmdNhDnpBanalKXOb8OSkYuz9Fwg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=getcruise.com; spf=pass smtp.mailfrom=getcruise.com; dkim=pass (2048-bit key) header.d=getcruise.com header.i=@getcruise.com header.b=IS+HFdsh; dkim=pass (2048-bit key) header.d=getcruise.com header.i=@getcruise.com header.b=FKc8QEMR; arc=none smtp.client-ip=205.220.181.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=getcruise.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=getcruise.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=getcruise.com header.i=@getcruise.com header.b="IS+HFdsh"; dkim=pass (2048-bit key) header.d=getcruise.com header.i=@getcruise.com header.b="FKc8QEMR" Received: from pps.filterd (m0286621.ppops.net [127.0.0.1]) by mx0b-003ede02.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41KMkoQg021656 for ; Tue, 20 Feb 2024 15:26:55 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=getcruise.com; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=ppemail; bh=3+MVDzdQGcTG8ZVcZlnHFI DI4xMMVPhSvdDkNAusK/M=; b=IS+HFdshpiUFjqz6oQOU68b8btS9DTfbRNqrDt FCi02O1Ve1xzZrGFhXU467eyixozIPvfJ3Whimxj7FIKU9sbzsU6vq+W7YapqM6l D8m/fFwAdgB9xANDJGk0zgQf2dWX80S5CMjkbJ61q6TaFzleSFRetySenvmEAQoa TPYJU/5id2g/c8lfXhvgJcniJ6Pn2FV0XtWid0OAeD6Snsz0GKXDvNzB8G6l/wD1 /hj4P7I9X6gPULcIhu3RU2uKd+SwckuVipTcnWSmkUMfR6FQJMYcOcCoZZooro5h l48aVaU6AbpmieJu9PB1s+PV2ww55NgaK1Yl2of+LkXOUuuA== Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by mx0b-003ede02.pphosted.com (PPS) with ESMTPS id 3wd563g1fu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 20 Feb 2024 15:26:55 -0800 (PST) Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-68fa064556eso4482706d6.3 for ; Tue, 20 Feb 2024 15:26:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=getcruise.com; s=google; t=1708471614; x=1709076414; darn=lists.linux.dev; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=3+MVDzdQGcTG8ZVcZlnHFIDI4xMMVPhSvdDkNAusK/M=; b=FKc8QEMRG/5lh6q33DUdSer3ReWTXYq2XtzbMVjpvLoOzni4/8bCEQMxb24CA/IGJ1 QYZ7VvW9QDLkEb0fK2Ip/mvfFRUBs9q3A8XnCiTU4ADXc6bi2sagrZmoZn+5Pvaj+Hot EtNnBYW9zi15nhL7Zkab6RU3KvfS7t3BEiFlQTtyPEbK4VZ8miD6jwS5huXXlPqaM7Zi eroV5XM3O02LYIZ0jAhmg7gsNVdalgpyeW/A9pXX4i+5GeOrW4lEbF39lE5HkITX/sjo HPm80x67FFxJmX6jnlE5ruOuwj69FsPYCeP0Fj7UoImZ7/9PLGEPYs0d9ODcnVSOng0L hEPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708471614; x=1709076414; h=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=3+MVDzdQGcTG8ZVcZlnHFIDI4xMMVPhSvdDkNAusK/M=; b=D0RJ07UerYQHmg9DRBQ4wjk3SDslAPpEBq6OxPT+1AnaGhapSPWS9s43g2OWvucU7+ yHMJwiRa8q7isPOL9npneToOPRq4tWHjwOb4u1LDxBk2HmkveAZsWUQ6Losal/+lZJ7q ArXpr3SjzgFJ621RykQ1bXEWKxHe+cRl2/KChtVAT2p51AbHvyTxR/CeFSj3mGqmuqCV p0eR2WK1Szl1YQPH394gQ/xzSU5PmkX/vtv27UzAbTpdyw0yool8QUPuQzcfXXu5z3RQ yakMkLCRYY/sKo/ZgfKUBwL52FLPwJ0utf3jKKziVOZ3hW93aoGYPCQFNKluF9GkyWz0 /qHQ== X-Gm-Message-State: AOJu0Yx2TjCXNmLE2FzXqGSRB4RqHJcxhTo517ZH2eppCYUkZT5toEgc 6Fg0C1LR5iymgpr14ECh+Y7dItiy2SbP+FrW4W0eFXMuVXlcpjEUcFKz+9C9oqQ8W4qlMt//Dzp rsKp6WhTTLRXuXrlHO0crebjoxR9vsYTPDq5Qz3I9hZrogbAweghCBiJLt/RxWQ6c3/8D44JLQm mN/opdiAeZ1P65J7FPwfftjhq8qG8Jw5+xEe5gA7faPfGmgqU= X-Received: by 2002:a0c:9792:0:b0:68f:5091:872f with SMTP id l18-20020a0c9792000000b0068f5091872fmr10267174qvd.53.1708471613740; Tue, 20 Feb 2024 15:26:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IEgzVPGRyvRIduVzLqJu/r5rKlL4EUJ06hUHbJUdAYotAkQ1j4hdpAKzRk9UZm5NHSYfJEUwg== X-Received: by 2002:a0c:9792:0:b0:68f:5091:872f with SMTP id l18-20020a0c9792000000b0068f5091872fmr10267158qvd.53.1708471613335; Tue, 20 Feb 2024 15:26:53 -0800 (PST) Received: from localhost.localdomain ([140.177.180.84]) by smtp.gmail.com with ESMTPSA id mb10-20020a056214550a00b0068f85706ecfsm1931983qvb.104.2024.02.20.15.26.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 15:26:53 -0800 (PST) From: Steve Schrock To: ofono@lists.linux.dev Cc: Steve Schrock Subject: [PATCH 3/4] qmimodem: Use l_queue instead of GQueue Date: Tue, 20 Feb 2024 23:25:28 +0000 Message-Id: <20240220232529.128477-3-steve.schrock@getcruise.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240220232529.128477-1-steve.schrock@getcruise.com> References: <20240220232529.128477-1-steve.schrock@getcruise.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: PdX7ZNEXHF_tBEEIul7OzGT42_txzuVl X-Proofpoint-GUID: PdX7ZNEXHF_tBEEIul7OzGT42_txzuVl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-20_06,2024-02-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 spamscore=0 lowpriorityscore=0 priorityscore=1501 clxscore=1015 phishscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402200167 Now a find that is immediately followed by a removal will perform two lookups instead of of one. The queues will be small so this should not make a noticeable difference. --- drivers/qmimodem/qmi.c | 184 ++++++++++++++++------------------------- 1 file changed, 73 insertions(+), 111 deletions(-) diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c index b8f019cc..95c9ef75 100644 --- a/drivers/qmimodem/qmi.c +++ b/drivers/qmimodem/qmi.c @@ -62,10 +62,10 @@ struct qmi_device { bool close_on_unref; guint read_watch; guint write_watch; - GQueue *req_queue; - GQueue *control_queue; - GQueue *service_queue; - GQueue *discovery_queue; + struct l_queue *req_queue; + struct l_queue *control_queue; + struct l_queue *service_queue; + struct l_queue *discovery_queue; uint8_t next_control_tid; uint16_t next_service_tid; qmi_debug_func_t debug_func; @@ -213,7 +213,7 @@ static struct qmi_request *__request_alloc(uint8_t service, return req; } -static void __request_free(gpointer data, gpointer user_data) +static void __request_free(void *data) { struct qmi_request *req = data; @@ -221,15 +221,15 @@ static void __request_free(gpointer data, gpointer user_data) l_free(req); } -static gint __request_compare(gconstpointer a, gconstpointer b) +static bool __request_compare(const void *a, const void *b) { const struct qmi_request *req = a; uint16_t tid = GPOINTER_TO_UINT(b); - return req->tid - tid; + return req->tid == tid; } -static void __discovery_free(gpointer data, gpointer user_data) +static void __discovery_free(void *data) { struct discovery *d = data; qmi_destroy_func_t destroy = d->destroy; @@ -614,7 +614,7 @@ static gboolean can_write_data(GIOChannel *channel, GIOCondition cond, struct qmi_request *req; ssize_t bytes_written; - req = g_queue_pop_head(device->req_queue); + req = l_queue_pop_head(device->req_queue); if (!req) return FALSE; @@ -631,14 +631,14 @@ static gboolean can_write_data(GIOChannel *channel, GIOCondition cond, hdr = req->buf; if (hdr->service == QMI_SERVICE_CONTROL) - g_queue_push_tail(device->control_queue, req); + l_queue_push_tail(device->control_queue, req); else - g_queue_push_tail(device->service_queue, req); + l_queue_push_tail(device->service_queue, req); l_free(req->buf); req->buf = NULL; - if (g_queue_get_length(device->req_queue) > 0) + if (l_queue_length(device->req_queue) > 0) return TRUE; return FALSE; @@ -688,7 +688,7 @@ static uint16_t __request_submit(struct qmi_device *device, req->tid = hdr->transaction; } - g_queue_push_tail(device->req_queue, req); + l_queue_push_tail(device->req_queue, req); wakeup_writer(device); @@ -758,7 +758,6 @@ static void handle_packet(struct qmi_device *device, const struct qmi_control_hdr *control = buf; const struct qmi_message_hdr *msg; unsigned int tid; - GList *list; /* Ignore control messages with client identifier */ if (hdr->client != 0x00) @@ -779,19 +778,16 @@ static void handle_packet(struct qmi_device *device, return; } - list = g_queue_find_custom(device->control_queue, - GUINT_TO_POINTER(tid), __request_compare); - if (!list) + req = l_queue_find(device->control_queue, __request_compare, + GUINT_TO_POINTER(tid)); + if (!req) return; - req = list->data; - - g_queue_delete_link(device->control_queue, list); + l_queue_remove(device->control_queue, req); } else { const struct qmi_service_hdr *service = buf; const struct qmi_message_hdr *msg; unsigned int tid; - GList *list; msg = buf + QMI_SERVICE_HDR_SIZE; @@ -808,20 +804,18 @@ static void handle_packet(struct qmi_device *device, return; } - list = g_queue_find_custom(device->service_queue, - GUINT_TO_POINTER(tid), __request_compare); - if (!list) + req = l_queue_find(device->service_queue, __request_compare, + GUINT_TO_POINTER(tid)); + if (!req) return; - req = list->data; - - g_queue_delete_link(device->service_queue, list); + l_queue_remove(device->service_queue, req); } if (req->callback) req->callback(message, length, data, req->user_data); - __request_free(req, NULL); + __request_free(req); } static gboolean received_data(GIOChannel *channel, GIOCondition cond, @@ -885,16 +879,16 @@ static void read_watch_destroy(gpointer user_data) static void __qmi_device_discovery_started(struct qmi_device *device, struct discovery *d) { - g_queue_push_tail(device->discovery_queue, d); + l_queue_push_tail(device->discovery_queue, d); } static void __qmi_device_discovery_complete(struct qmi_device *device, struct discovery *d) { - if (g_queue_remove(device->discovery_queue, d) != TRUE) + if (l_queue_remove(device->discovery_queue, d) != TRUE) return; - __discovery_free(d, NULL); + __discovery_free(d); } static void service_destroy(gpointer data) @@ -945,10 +939,10 @@ struct qmi_device *qmi_device_new(int fd) g_io_channel_unref(device->io); - device->req_queue = g_queue_new(); - device->control_queue = g_queue_new(); - device->service_queue = g_queue_new(); - device->discovery_queue = g_queue_new(); + device->req_queue = l_queue_new(); + device->control_queue = l_queue_new(); + device->service_queue = l_queue_new(); + device->discovery_queue = l_queue_new(); device->service_list = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, service_destroy); @@ -979,17 +973,10 @@ void qmi_device_unref(struct qmi_device *device) __debug_device(device, "device %p free", device); - g_queue_foreach(device->control_queue, __request_free, NULL); - g_queue_free(device->control_queue); - - g_queue_foreach(device->service_queue, __request_free, NULL); - g_queue_free(device->service_queue); - - g_queue_foreach(device->req_queue, __request_free, NULL); - g_queue_free(device->req_queue); - - g_queue_foreach(device->discovery_queue, __discovery_free, NULL); - g_queue_free(device->discovery_queue); + l_queue_destroy(device->control_queue, __request_free); + l_queue_destroy(device->service_queue, __request_free); + l_queue_destroy(device->req_queue, __request_free); + l_queue_destroy(device->discovery_queue, __discovery_free); if (device->write_watch > 0) g_source_remove(device->write_watch); @@ -1212,26 +1199,22 @@ done: static struct qmi_request *find_control_request(struct qmi_device *device, uint16_t tid) { - GList *list; struct qmi_request *req = NULL; unsigned int _tid = tid; if (_tid != 0) { - list = g_queue_find_custom(device->req_queue, - GUINT_TO_POINTER(_tid), __request_compare); - - if (list) { - req = list->data; - g_queue_delete_link(device->req_queue, list); - } else { - list = g_queue_find_custom(device->control_queue, - GUINT_TO_POINTER(_tid), __request_compare); - - if (list) { - req = list->data; - g_queue_delete_link(device->control_queue, - list); - } + req = l_queue_find(device->req_queue, __request_compare, + GUINT_TO_POINTER(_tid)); + + if (req) + l_queue_remove(device->req_queue, req); + else { + req = l_queue_find(device->control_queue, + __request_compare, + GUINT_TO_POINTER(_tid)); + + if (req) + l_queue_remove(device->control_queue, req); } } @@ -1255,7 +1238,7 @@ static gboolean discover_reply(gpointer user_data) __qmi_device_discovery_complete(device, &data->super); if (req) - __request_free(req, NULL); + __request_free(req); return FALSE; } @@ -1983,7 +1966,7 @@ static gboolean service_create_reply(gpointer user_data) __qmi_device_discovery_complete(device, &data->super); if (req) - __request_free(req, NULL); + __request_free(req); return FALSE; } @@ -2309,9 +2292,7 @@ uint16_t qmi_service_send(struct qmi_service *service, if (!device) return 0; - data = g_try_new0(struct service_send_data, 1); - if (!data) - return 0; + data = l_new(struct service_send_data, 1); data->func = func; data->user_data = user_data; @@ -2335,7 +2316,6 @@ bool qmi_service_cancel(struct qmi_service *service, uint16_t id) unsigned int tid = id; struct qmi_device *device; struct qmi_request *req; - GList *list; if (!service || !tid) return false; @@ -2347,59 +2327,44 @@ bool qmi_service_cancel(struct qmi_service *service, uint16_t id) if (!device) return false; - list = g_queue_find_custom(device->req_queue, - GUINT_TO_POINTER(tid), __request_compare); - if (list) { - req = list->data; - - g_queue_delete_link(device->req_queue, list); - } else { - list = g_queue_find_custom(device->service_queue, - GUINT_TO_POINTER(tid), __request_compare); - if (!list) + req = l_queue_find(device->req_queue, __request_compare, + GUINT_TO_POINTER(tid)); + if (req) + l_queue_remove(device->req_queue, req); + else { + req = l_queue_find(device->service_queue, __request_compare, + GUINT_TO_POINTER(tid)); + if (!req) return false; - req = list->data; - - g_queue_delete_link(device->service_queue, list); + l_queue_remove(device->service_queue, req); } service_send_free(req->user_data); - __request_free(req, NULL); + __request_free(req); return true; } -static GQueue *remove_client(GQueue *queue, uint8_t client) +static bool remove_req_if_match(void* data, void* user_data) { - GQueue *new_queue; - GList *list; - - new_queue = g_queue_new(); - - while (1) { - struct qmi_request *req; - - list = g_queue_pop_head_link(queue); - if (!list) - break; - - req = list->data; - - if (!req->client || req->client != client) { - g_queue_push_tail_link(new_queue, list); - continue; - } + struct qmi_request *req = data; + uint8_t client = GPOINTER_TO_UINT(user_data); - service_send_free(req->user_data); + if (!req->client || req->client != client) + return false; - __request_free(req, NULL); - } + service_send_free(req->user_data); + __request_free(req); - g_queue_free(queue); + return true; +} - return new_queue; +static void remove_client(struct l_queue *queue, uint8_t client) +{ + l_queue_foreach_remove(queue, remove_req_if_match, + GUINT_TO_POINTER(client)); } bool qmi_service_cancel_all(struct qmi_service *service) @@ -2416,11 +2381,8 @@ bool qmi_service_cancel_all(struct qmi_service *service) if (!device) return false; - device->req_queue = remove_client(device->req_queue, - service->client_id); - - device->service_queue = remove_client(device->service_queue, - service->client_id); + remove_client(device->req_queue, service->client_id); + remove_client(device->service_queue, service->client_id); return true; } From patchwork Tue Feb 20 23:25:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Schrock X-Patchwork-Id: 13564766 Received: from mx0b-003ede02.pphosted.com (mx0b-003ede02.pphosted.com [205.220.181.153]) (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 4752C76414 for ; Tue, 20 Feb 2024 23:48:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.181.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708472941; cv=none; b=LT8k8L6SVB9XoxyICuSGX6w95LPPieNw0zqwn6NjWwFhGPtvC7WzHA5uiAF/TdMdPdh2GXTaYIpcEvBmN5XpUayZxyIixrE3BLHhkLT2m9dT7zCkvrZ9ODjOMKzwPADe97QpKBPZkJsR0RFwMdKFWzRg7UY8+bciC3UsBaDpapE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708472941; c=relaxed/simple; bh=bVLMIYks2Iq7lgx5RnEUMqgnT9p67T3jutQkuawJXpk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=MxRdIW8G6OYOXkUyuHy4j1gT56Ef8TYENsh14DVfgUkIZfdm7oZrnRI29yRJtGmMwY8QmHwZn1gwVQ1QAw3wZ4L/1NTwqV6WWnpodCD1LrS1pO+FRH4SnYSMfFALXT84HV6eiv8BWROyvw1MEm6aWOqspS/mmMESX6SATkhGe3s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=getcruise.com; spf=pass smtp.mailfrom=getcruise.com; dkim=pass (2048-bit key) header.d=getcruise.com header.i=@getcruise.com header.b=MJsiU7qf; dkim=pass (2048-bit key) header.d=getcruise.com header.i=@getcruise.com header.b=XC03uud2; arc=none smtp.client-ip=205.220.181.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=getcruise.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=getcruise.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=getcruise.com header.i=@getcruise.com header.b="MJsiU7qf"; dkim=pass (2048-bit key) header.d=getcruise.com header.i=@getcruise.com header.b="XC03uud2" Received: from pps.filterd (m0286620.ppops.net [127.0.0.1]) by mx0b-003ede02.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41KMq5l4013651 for ; Tue, 20 Feb 2024 15:26:55 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=getcruise.com; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=ppemail; bh=3Ql6Zk8hQLNbEi3k/t/276 AGKtWK0ed5yf44KsJmbko=; b=MJsiU7qfa8M5dLgvTOpWpYJ16TDkIJwLBzeqw5 Ttw4HzbIak+Caf78YfJ6lAnHNGV3/3CKIMPjXSwkNM1rGgZNO8Tf/daCDsjRSu93 /ZLqcD5TOtnQp8TvGxw1iECBBmAoikdvSoblclvNmEWfhfaHGQqYt12URWeB1M4w LsIphvMKANlZTt6lEd5JV4zWrYPxwyinAdktgqfUMh3fjjQyKxb2vVfHySpC/cwS 9UDMshVfuPuUbozAvX6/mY3RuIXuUX6mxj2DZqYHVe2kJ1XkeWY7iCaArDMjmBhU IRLwjGVsR3q8wSK02Y5WEr/6o/j30Wns4rilxf5gwIxztonw== Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by mx0b-003ede02.pphosted.com (PPS) with ESMTPS id 3wd58hr196-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 20 Feb 2024 15:26:55 -0800 (PST) Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-68f95177e25so14935866d6.2 for ; Tue, 20 Feb 2024 15:26:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=getcruise.com; s=google; t=1708471614; x=1709076414; darn=lists.linux.dev; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=3Ql6Zk8hQLNbEi3k/t/276AGKtWK0ed5yf44KsJmbko=; b=XC03uud2MlA0zOLs1xUtTL9ihHZaOQCpisudcUIPZ61MqDj/CA6DKYtehwYYvrlAxH Ky9AIG82Yazp+UdeV1q5Tajxo1mIzzioMLNck9J2fly7yJYHhLmETw+8YCG7A1sotdGF qTBOY2dq6rC9jZTfy5sMuxSA/ZABF3Z/RQT7+tUQf6jCc3bq1ovzcNAJPTNLjo5nRPxM I5KWTAliz2AVjZVNPkLLwa6TmDraUDd2RHQ7xrdTGilt7u5L6UavceoTlbqDyeBWSHYp J/n8Bm8B2wnRr30QFv0NUwj04/uNcHHWq2XJkqkYjbiHCUgvAS4vm+e6/KUblFuVb5fc /v6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708471614; x=1709076414; h=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=3Ql6Zk8hQLNbEi3k/t/276AGKtWK0ed5yf44KsJmbko=; b=dHb5rnO/BP1G2cLCXRfS+QSrOse5oGjtu/EN7uma/oZAbwyUKUIpuBg5neUTSFmD2P GlUlDpT2juTDzd0cYhl+IMS/dPSeC3axG0eyYOcXiKuGQKoYjM3fRctBwo71n3OFn0N2 U6cc7iyvlKp8siBaoVqGeggGLuk4Ns+uTNx/SHIllOKUR86k8ovYePFFXMd3GDyLSY3j cgeI6mSD1dVqMUoB6TQlmZxOYZCo8FQxjGPTylfq4uqCmfPRbrujFDHW+lrfMSNXlPEo Vr6vt/WCnvTZzEgZ2UwmwpT7Kcz6zsXT6Xw2zhU+TjjNFtpdAiqBW7/TOWK2h+xLXn2H XqQA== X-Gm-Message-State: AOJu0YzYPzy8iaKLxqwtLX/IOTJ0bRcXuZ9kLNZekwI0naoc2+MDIfx0 0dxjv5JVRvVeIg4tlVjyIRV8em//Yg596h/d/QBc/Kxt8ymnibqPappWI3f6Tl9TWrgeTX3g1kg +hl7wWpOkSLoKHi4wD5UNXvnD+//s8l5Xla5Vd7gtQ6IkTinUE4PgFdp2FOeq3Eu0BXX5OxJ1oX fLWLlCryzh8VtnxNtyUSmyLXhen+EZgv388BEig/Cux3h1bCI= X-Received: by 2002:a05:6214:5090:b0:68f:8808:8d04 with SMTP id kk16-20020a056214509000b0068f88088d04mr5493852qvb.29.1708471614538; Tue, 20 Feb 2024 15:26:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKsoKqL8cqXeRAeyqQF3GLQIUsAl8pgO5Q/1WeZ0I5S319u7036TXr/5sdzN2kepSWjocTeQ== X-Received: by 2002:a05:6214:5090:b0:68f:8808:8d04 with SMTP id kk16-20020a056214509000b0068f88088d04mr5493826qvb.29.1708471614060; Tue, 20 Feb 2024 15:26:54 -0800 (PST) Received: from localhost.localdomain ([140.177.180.84]) by smtp.gmail.com with ESMTPSA id mb10-20020a056214550a00b0068f85706ecfsm1931983qvb.104.2024.02.20.15.26.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 15:26:53 -0800 (PST) From: Steve Schrock To: ofono@lists.linux.dev Cc: Steve Schrock Subject: [PATCH 4/4] qmimodem: Use l_hashmap instead of GHashTable Date: Tue, 20 Feb 2024 23:25:29 +0000 Message-Id: <20240220232529.128477-4-steve.schrock@getcruise.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240220232529.128477-1-steve.schrock@getcruise.com> References: <20240220232529.128477-1-steve.schrock@getcruise.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-GUID: kARcviL4wfmLepIJyj4Q1q8PvWlYG313 X-Proofpoint-ORIG-GUID: kARcviL4wfmLepIJyj4Q1q8PvWlYG313 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-20_06,2024-02-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxlogscore=945 bulkscore=0 priorityscore=1501 mlxscore=0 malwarescore=0 phishscore=0 spamscore=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402200168 --- drivers/qmimodem/qmi.c | 90 ++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 39 deletions(-) diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c index 95c9ef75..30c39603 100644 --- a/drivers/qmimodem/qmi.c +++ b/drivers/qmimodem/qmi.c @@ -75,7 +75,7 @@ struct qmi_device { char *version_str; struct qmi_version *version_list; uint8_t version_count; - GHashTable *service_list; + struct l_hashmap *service_list; unsigned int release_users; qmi_shutdown_func_t shutdown_func; void *shutdown_user_data; @@ -255,20 +255,23 @@ static gint __notify_compare(gconstpointer a, gconstpointer b) return notify->id - id; } -static gboolean __service_compare_shared(gpointer key, gpointer value, - gpointer user_data) +struct service_find_by_type_data { + unsigned int type; + struct qmi_service *found_service; +}; + +static void __service_find_by_type(const void *key, void *value, + void *user_data) { struct qmi_service *service = value; - uint8_t type = GPOINTER_TO_UINT(user_data); + struct service_find_by_type_data *data = user_data; /* ignore those that are in process of creation */ if (GPOINTER_TO_UINT(key) & 0x80000000) - return FALSE; - - if (service->type == type) - return TRUE; + return; - return FALSE; + if (service->type == data->type) + data->found_service = service; } static const char *__service_type_to_string(uint8_t type) @@ -695,7 +698,7 @@ static uint16_t __request_submit(struct qmi_device *device, return req->tid; } -static void service_notify(gpointer key, gpointer value, gpointer user_data) +static void service_notify(const void *key, void *value, void *user_data) { struct qmi_service *service = value; struct qmi_result *result = user_data; @@ -732,15 +735,16 @@ static void handle_indication(struct qmi_device *device, result.length = length; if (client_id == 0xff) { - g_hash_table_foreach(device->service_list, - service_notify, &result); + l_hashmap_foreach(device->service_list, service_notify, + &result); return; } hash_id = service_type | (client_id << 8); - service = g_hash_table_lookup(device->service_list, + service = l_hashmap_lookup(device->service_list, GUINT_TO_POINTER(hash_id)); + if (!service) return; @@ -891,7 +895,7 @@ static void __qmi_device_discovery_complete(struct qmi_device *device, __discovery_free(d); } -static void service_destroy(gpointer data) +static void service_destroy(void *data) { struct qmi_service *service = data; @@ -944,8 +948,7 @@ struct qmi_device *qmi_device_new(int fd) device->service_queue = l_queue_new(); device->discovery_queue = l_queue_new(); - device->service_list = g_hash_table_new_full(g_direct_hash, - g_direct_equal, NULL, service_destroy); + device->service_list = l_hashmap_new(); device->next_control_tid = 1; device->next_service_tid = 256; @@ -990,7 +993,7 @@ void qmi_device_unref(struct qmi_device *device) if (device->shutdown_source) g_source_remove(device->shutdown_source); - g_hash_table_destroy(device->service_list); + l_hashmap_destroy(device->service_list, service_destroy); l_free(device->version_str); l_free(device->version_list); @@ -1930,11 +1933,9 @@ static void service_create_shared_pending_reply(struct qmi_device *device, struct qmi_service *service) { gpointer key = GUINT_TO_POINTER(type | 0x80000000); - GList **shared = g_hash_table_lookup(device->service_list, key); + GList **shared = l_hashmap_remove(device->service_list, key); GList *l; - g_hash_table_steal(device->service_list, key); - for (l = *shared; l; l = l->next) { struct service_create_shared_data *shared_data = l->data; @@ -1977,6 +1978,7 @@ static void service_create_callback(uint16_t message, uint16_t length, struct service_create_data *data = user_data; struct qmi_device *device = data->device; struct qmi_service *service = NULL; + struct qmi_service *old_service = NULL; const struct qmi_result_code *result_code; const struct qmi_client_id *client_id; uint16_t len; @@ -2015,8 +2017,11 @@ static void service_create_callback(uint16_t message, uint16_t length, hash_id = service->type | (service->client_id << 8); - g_hash_table_replace(device->service_list, - GUINT_TO_POINTER(hash_id), service); + l_hashmap_replace(device->service_list, GUINT_TO_POINTER(hash_id), + service, (void **) &old_service); + + if (old_service) + service_destroy(old_service); done: service_create_shared_pending_reply(device, data->type, service); @@ -2072,7 +2077,7 @@ static bool service_create(struct qmi_device *device, __qmi_device_discovery_started(device, &data->super); /* Mark service creation as pending */ - g_hash_table_insert(device->service_list, + l_hashmap_insert(device->service_list, GUINT_TO_POINTER(type_val | 0x80000000), shared); return true; @@ -2099,7 +2104,8 @@ bool qmi_service_create_shared(struct qmi_device *device, uint16_t type, qmi_create_func_t func, void *user_data, qmi_destroy_func_t destroy) { - gpointer service; + GList **l = NULL; + struct qmi_service *service = NULL; unsigned int type_val = type; if (!device || !func) @@ -2108,15 +2114,27 @@ bool qmi_service_create_shared(struct qmi_device *device, uint16_t type, if (type == QMI_SERVICE_CONTROL) return false; - service = g_hash_table_lookup(device->service_list, + l = l_hashmap_lookup(device->service_list, GUINT_TO_POINTER(type_val | 0x80000000)); - if (!service) { - service = g_hash_table_find(device->service_list, - __service_compare_shared, GUINT_TO_POINTER(type_val)); + + if (!l) { + /* + * There is no way to find in an l_hashmap using a custom + * function. Instead we use a temporary struct to store the + * found service. This is not very clean, but we expect this + * code to be refactored soon. + */ + struct service_find_by_type_data data; + + data.type = type_val; + data.found_service = NULL; + l_hashmap_foreach(device->service_list, __service_find_by_type, + &data); + service = data.found_service; } else type_val |= 0x80000000; - if (service) { + if (l || service) { struct service_create_shared_data *data; data = l_new(struct service_create_shared_data, 1); @@ -2127,18 +2145,12 @@ bool qmi_service_create_shared(struct qmi_device *device, uint16_t type, data->user_data = user_data; data->destroy = destroy; - if (!data) - return false; - if (!(type_val & 0x80000000)) { data->service = qmi_service_ref(service); data->timeout = g_timeout_add( 0, service_create_shared_reply, data); - } else { - GList **l = service; - + } else *l = g_list_prepend(*l, data); - } __qmi_device_discovery_started(device, &data->super); @@ -2197,8 +2209,8 @@ void qmi_service_unref(struct qmi_service *service) hash_id = service->type | (service->client_id << 8); - g_hash_table_steal(service->device->service_list, - GUINT_TO_POINTER(hash_id)); + l_hashmap_remove(service->device->service_list, + GUINT_TO_POINTER(hash_id)); service->device->release_users++; @@ -2347,7 +2359,7 @@ bool qmi_service_cancel(struct qmi_service *service, uint16_t id) return true; } -static bool remove_req_if_match(void* data, void* user_data) +static bool remove_req_if_match(void *data, void *user_data) { struct qmi_request *req = data; uint8_t client = GPOINTER_TO_UINT(user_data);