Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2112232rdh; Tue, 26 Sep 2023 12:50:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJat+pYHymc77ovo/ieomVM+f0EWcyHVSjusCY+r+7si5D+nkifa3w2tame3P6YAKOPmfs X-Received: by 2002:a17:90b:3146:b0:268:4485:c868 with SMTP id ip6-20020a17090b314600b002684485c868mr8690199pjb.49.1695757854233; Tue, 26 Sep 2023 12:50:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695757854; cv=none; d=google.com; s=arc-20160816; b=KkpVCgY89+lXXrbqoutj8AcQwjdIj5/MnywopZg131CMJaKQCKWdgZcPbegYSdDr9G UqBo2BeYEupqa2leXsS2lDkXy67dOQEWP2qjrpyy9S89pTi/D7FSIyfRatl3BVB2J8oJ iwVo3m3Ovt8A1yw4+9mR0uy3PD3/ydIC04fnfrfaLqt7zEP9Krug7zUQCFfOfICNiK1E CRJV1wwM5aw1nRDYTyC0Leu5HsWMsOea7XKx4WDx/i63VMHH7eZ7svVXtUB7EIjhKZ4h bAeNY5aPttaHUQHbI+yLNEgsRB3WRRYa+NPYuD+PXbpztDFSRV8c7tifFIGHamojYSMK E2EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=avIZNP/kVwTxfUJrkUHAHZVU2AnGKIlWeQ7L/YwCkE0=; fh=NqgSwVQYrXOUoc4nMnLezcCdhGhmT7BXAt0Uvb81MWk=; b=kK/32ltPgL5/XAueMN2uy+grMIeHMXItaPVKKsMos72ts/4uoyR9SBzInEOKq/jhEF EP92r2JP6TN19g2kYBhptZfEeAM8tfY0JKM7/FcR/8seY2uB3p/5k/WeFk3msVaiOr05 MkX66fcUk6AwpAT+2JRts9y/LQnBXgZQ+8yutkVpCNRCmFp0DUrndLGNYcIUzbicfg7U Nh+tNI4BG9ILS398B5ntV/HJARmCU6oLhmuKNaXRoK8B3igz12cy4rKH7UJUqM7IDix9 E2sMalr6lH5coS923e07cHKwuPuivlTbMNaSlsmMBf7mJylt8xGjIXEuPlyhCkUhZZFN UblQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HM34oUXH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id j4-20020a17090a694400b002744e9b7a22si15382137pjm.9.2023.09.26.12.50.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 12:50:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HM34oUXH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 964CD822CB31; Tue, 26 Sep 2023 10:37:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233837AbjIZRh4 (ORCPT + 99 others); Tue, 26 Sep 2023 13:37:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231659AbjIZRhw (ORCPT ); Tue, 26 Sep 2023 13:37:52 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 249E8DC; Tue, 26 Sep 2023 10:37:46 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1c61c511cbeso7780335ad.1; Tue, 26 Sep 2023 10:37:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695749865; x=1696354665; darn=vger.kernel.org; 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=avIZNP/kVwTxfUJrkUHAHZVU2AnGKIlWeQ7L/YwCkE0=; b=HM34oUXHfI2Zs87uI9vWG9+KcDkKcaPMwusPKXS4UdY9Rh7edyNscZYGcvz799BlnG EnTxvSG6A4Wewf0Z2WDO6H79+Up2+fcAT3IWE/v7xYwu+1ycoJSj2vtW8ZUE+RIxrJXR cjGDGM6AYjGaN+LjXZoml/TwwA/hVuKFyEZeDAwCR5ZXe3IHWMyabWOA5jwWNnjYI8NA LWntGGdgecpvTD0OZfLh2LYzpfiYQN54wRiqVuWiwjd27Jmh5xpCgfzCVnGGMJ3oANuA cMaAL/mJxUnq252VEB7FoAiT240tk516U17CTsavRDfH4MNp+PNIuFi7nV0G4BafYXUl ZHtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695749865; x=1696354665; 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=avIZNP/kVwTxfUJrkUHAHZVU2AnGKIlWeQ7L/YwCkE0=; b=aXL6Ve+cgKFvOHfPKfIU+8EafXZT/KEin6X6JSQv2HSUewdMye5QS39cXAUURMDEKk etjaqfB5SWqYHQSgQ504Y6MJdBZ/FiO7hohBX8p0VGIgqCiTnogMpapyRC2qj61bHXAe ux5+xZv5gZftM35gxpjfs+pFDwPGYNa89ORAmBAoTv4M5dkxRNej8Jci1QYMGbxGml0P WKZQdTdXtX6Ydyb5A4FdX4CeDhRRfG9wBeAsfa4OI7kZzM6JuIlWDtEU3AsQgju0TxXv RcOl/46qasIa7NQLC+ayS/6g7zCYJi1Ji5RnrQ1Wl1F52xIqZK3KqjTF4BMdp9fbWaKu 3BSQ== X-Gm-Message-State: AOJu0YzfVu1Lf/HCbSLSd2//XJK3gAPbTSIj2Dl7vrTR55x1I7CF2ay+ WB/vzRkEMzzZfBivAHfVe7E= X-Received: by 2002:a17:902:d4c5:b0:1c3:a4f2:7c99 with SMTP id o5-20020a170902d4c500b001c3a4f27c99mr11781313plg.4.1695749865561; Tue, 26 Sep 2023 10:37:45 -0700 (PDT) Received: from localhost.localdomain ([140.116.154.65]) by smtp.gmail.com with ESMTPSA id jw18-20020a170903279200b001adf6b21c77sm11310927plb.107.2023.09.26.10.37.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 10:37:44 -0700 (PDT) From: Kuan-Wei Chiu To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: amitk@kernel.org, rui.zhang@intel.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Kuan-Wei Chiu Subject: [PATCH v2] tools/thermal: remove unused 'mds' and 'nrhandler' variables Date: Wed, 27 Sep 2023 01:37:36 +0800 Message-Id: <20230926173736.1142420-1-visitorckw@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <93c87b5c-ae8f-d27d-0342-faa884a3142e@linaro.org> References: <93c87b5c-ae8f-d27d-0342-faa884a3142e@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 26 Sep 2023 10:37:55 -0700 (PDT) In the previous code, the 'mds' and 'nrhandler' variables were not utilized in the codebase. Additionally, there was a potential NULL pointer dereference and memory leak due to improper handling of memory reallocation failure. This patch removes the unused 'mds' and 'nrhandler' variables along with the associated code, addressing the unused variable issue, NULL pointer dereference issue and the memory leak issue. Signed-off-by: Kuan-Wei Chiu --- Changes since v1: * Remove the unused 'mds' and 'nrhandler' variables along with the associated code. tools/thermal/lib/mainloop.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/tools/thermal/lib/mainloop.c b/tools/thermal/lib/mainloop.c index 94cbbcbd1c14..bf4c1b730d7b 100644 --- a/tools/thermal/lib/mainloop.c +++ b/tools/thermal/lib/mainloop.c @@ -9,7 +9,6 @@ #include "log.h" static int epfd = -1; -static unsigned short nrhandler; static sig_atomic_t exit_mainloop; struct mainloop_data { @@ -18,8 +17,6 @@ struct mainloop_data { int fd; }; -static struct mainloop_data **mds; - #define MAX_EVENTS 10 int mainloop(unsigned int timeout) @@ -61,13 +58,6 @@ int mainloop_add(int fd, mainloop_callback_t cb, void *data) struct mainloop_data *md; - if (fd >= nrhandler) { - mds = realloc(mds, sizeof(*mds) * (fd + 1)); - if (!mds) - return -1; - nrhandler = fd + 1; - } - md = malloc(sizeof(*md)); if (!md) return -1; @@ -76,7 +66,6 @@ int mainloop_add(int fd, mainloop_callback_t cb, void *data) md->cb = cb; md->fd = fd; - mds[fd] = md; ev.data.ptr = md; if (epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev) < 0) { @@ -89,14 +78,9 @@ int mainloop_add(int fd, mainloop_callback_t cb, void *data) int mainloop_del(int fd) { - if (fd >= nrhandler) - return -1; - if (epoll_ctl(epfd, EPOLL_CTL_DEL, fd, NULL) < 0) return -1; - free(mds[fd]); - return 0; } -- 2.25.1