Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp3495799pxb; Wed, 14 Apr 2021 06:52:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrw/49snqj9d/FDqyJt0ZeD/CNw6g0PBC6jCInC5AFl5ijscjkauwrnXVCr9fTsnur6fm6 X-Received: by 2002:a17:906:3d41:: with SMTP id q1mr29241290ejf.282.1618408361260; Wed, 14 Apr 2021 06:52:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618408361; cv=none; d=google.com; s=arc-20160816; b=t2rqb6Fj9JxtbfjZHdw6Io9g7vlqrD1igBrCLewR5goj2xRXCxqRExHu7wcsuXiM9M ETxJsRh5cVNWu1ScGW7fhg9oHmiMz6N+3Ct8zZGqwXXgU4jBqbjk5vivaHTLtJIzTxWR oupDm+CU06rzwSmF1x437fY96M7fBBV4BwxaxVAON5jzgDqQt/NV3CP4pf0BuDW/1nmd cR9CCHrVKYdIZohuJa+RRyYLIdiH3jXxqmGooqJu2wHwD/BvvkzbekJddfI7YlW7SbM4 f4WPoulThEg5MyYLb27w6v9GxnJAu8CKWcuqdci2Dy+xThjUBoQM9VAVB/CN6wU2T0MA QVYg== 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=lM9tE4YP45dEebvaB1mn9Fj0H0g1RisXEtTq0o0OVEg=; b=c2b0wIBFtE6+2atxteznPzJhRdfaelESss7acltqX+kLXqb7jxEu/vcf3keNtCQhbc NnIBlE+ShzVNWCz/vzzrUL6H7gpAdRd6IibYrk76n5cQ+zfM/INfcopEeCDJNrl2imIq oCMV/ZRr15qmHbruHyiQDq5xQrlgsj3xGoc3hEi2Aru2urjV57nhmUceR11KLeIckixj UcAm7u68YFMY96irFJpc2ZwIhiAcBKO20y2lpQPpZVW7B/hJwSV3wx9eo84ImM2ZZTMF M9wyV1PxS5ficj5bwFiDSKprKPwfql643dfSYK3SHDo+NZDxiDFsdlqchscKRQ8xXcX4 Wmyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CnRNwfJW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a7si12678778edq.454.2021.04.14.06.52.14; Wed, 14 Apr 2021 06:52:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CnRNwfJW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347995AbhDNGeT (ORCPT + 99 others); Wed, 14 Apr 2021 02:34:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231831AbhDNGeS (ORCPT ); Wed, 14 Apr 2021 02:34:18 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03E4DC061574 for ; Tue, 13 Apr 2021 23:33:57 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id mh2so8096875ejb.8 for ; Tue, 13 Apr 2021 23:33:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lM9tE4YP45dEebvaB1mn9Fj0H0g1RisXEtTq0o0OVEg=; b=CnRNwfJWtnIxInVYy3BheuUuKlU/mLd0foWWQrwKR3EJVfzoxafwDXdLhuh2FT6ekj eRHZkZVCs+EaW9aO45cwqvr/LvEgoDS+nuGRokvGpLMWz2k4eqPNFM4QjZ0XUrblF6uj EVxPtJUFyp1xy1OqpazRyNeSWqQBRSyStD0FifqOsEt/dk6SuUlOAQf7ZwAtxFQsiASn 4UYqdjcnEmg/DEePZwdLxh0CFQCayzUKQ2sVM2Cc27iHsgQNTffhZ0NaI9L5zCvaanZF imQt3KHAGDNpmGS9wjIeTgnTf0A86mG/GD9w2tmWB5TPFYcKiSeed67ueSVniba188/o xOXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lM9tE4YP45dEebvaB1mn9Fj0H0g1RisXEtTq0o0OVEg=; b=D1yUekn9k/AEFU75tpXQRNcAAT8003oKtokqIbFKpGSEqkLG+BqFksfgFZrgBLUsCs 5QxYYI1kYPcpKVC9vO34XNZeUcqCl6c95Ih95+x/yEnqw2yeeGVuIp1qil+72egsadJZ d8WVn0qAayJOGeoXXxOAlBv4zqgp+tXnWD2wEXlJDZcXQQOeXk4dTHVWx7L7AO+Nocpi mbXiSK0sYcDtyYA7mDzBnlCdXRj4dMjlljdpmf9fxC2Jvmp4ZtYw59yyvObgWC3FPF1U lRPYGfbP9XceV5S5nNGIQDwytDf9xdoFC0mugMC9EvZDKNB2ZPgtNPAg/EWMsNx1nqtY 8Dfw== X-Gm-Message-State: AOAM532c2fyX4911znAWEwkOnQZZ+iien3OzVeMtxYjjd1aI+kOrgQo4 ubnSZaGlDYoZScrNJOmhiLA= X-Received: by 2002:a17:906:f8d7:: with SMTP id lh23mr10907676ejb.77.1618382030493; Tue, 13 Apr 2021 23:33:50 -0700 (PDT) Received: from linux.local (host-95-237-55-30.retail.telecomitalia.it. [95.237.55.30]) by smtp.gmail.com with ESMTPSA id u13sm9263724ejj.16.2021.04.13.23.33.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Apr 2021 23:33:49 -0700 (PDT) From: "Fabio M. De Francesco" To: Dan Carpenter Cc: Matthew Wilcox , Julia Lawall , outreachy-kernel@googlegroups.com, Greg Kroah-Hartman , linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [Outreachy kernel] [PATCH] :staging: rtl8723bs: Remove useless led_blink_hdl() Date: Wed, 14 Apr 2021 08:33:48 +0200 Message-ID: <2418632.vfNx7fMs9o@linux.local> In-Reply-To: <20210414052150.GO6021@kadam> References: <20210413155908.8691-1-fmdefrancesco@gmail.com> <3505455.GpAHCVcAZI@linux.local> <20210414052150.GO6021@kadam> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wednesday, April 14, 2021 7:21:50 AM CEST Dan Carpenter wrote: > On Tue, Apr 13, 2021 at 10:08:32PM +0200, Fabio M. De Francesco wrote: > > On Tuesday, April 13, 2021 9:48:44 PM CEST Matthew Wilcox wrote: > > > On Tue, Apr 13, 2021 at 09:45:03PM +0200, Fabio M. De Francesco wrote: > > > > 1) The driver doesn't call that function from anywhere else than > > > > the > > > > macro. 2) You have explained that the macro add its symbol to a > > > > slot > > > > in an array that would shift all the subsequent elements down if > > > > that > > > > macro is not used exactly in the line where it is. > > > > 3) Dan Carpenter said that that array is full of null functions (or > > > > empty slots?). > > > > > > > > Unless that function is called anonymously dereferencing its > > > > address > > > > from the position it occupies in the array, I'm not able to see > > > > what > > > > else means can any caller use. > > > > > > > > I know I have much less experience than you with C: what can go > > > > wrong? > > > > > > Here's where the driver calls that function: > > > > > > $ git grep wlancmds drivers/staging/rtl8723bs/ > > > drivers/staging/rtl8723bs/core/rtw_cmd.c:static struct cmd_hdl > > > wlancmds[] = { drivers/staging/rtl8723bs/core/rtw_cmd.c: > > > if > > > (pcmd->cmdcode < ARRAY_SIZE(wlancmds)) { > > > drivers/staging/rtl8723bs/core/rtw_cmd.c: > > > cmd_hdl > > > = wlancmds[pcmd->cmdcode].h2cfuns; > > > > OK, I had imagined an anonymous call from its location in the array (as > > I wrote in the last phrase of my message). However, I thought that it > > could have been an improbable possibility, not a real one. > > > > Linux uses a lot of interesting ideas that newcomers like me should > > learn. Things here are trickier than they appear at first sight. > > One trick would be to build the Smatch cross function database. > > https://www.spinics.net/lists/smatch/msg00568.html > > Then you could do: > > $ ~/path/to/smatch_data/db/smdb.py led_blink_hdl > file | caller | function | type | parameter | key | value | > drivers/staging/rtl8723bs/core/rtw_cmd.c | rtw_cmd_thread | > rtw_cmd_thread ptr cmd_hdl | INTERNAL | -1 | | > uchar(*)(struct adapter*, uchar*) > drivers/staging/rtl8188eu/core/rtw_cmd.c | rtw_cmd_thread | > rtw_cmd_thread ptr cmd_hdl | INTERNAL | -1 | | > uchar(*)(struct adapter*, uchar*) > drivers/staging/rtl8188eu/core/rtw_cmd.c | rtw_cmd_thread | > rtw_cmd_thread ptr cmd_hdl | BUF_SIZE | 1 | pbuf | > 1,4,6,8,12,14,16,19-20,23-24,48,740,884,892,900,960 > > > Which says that led_blink_hdl() is called as a function pointer called > "cmd_hdl" from rtw_cmd_thread(). > > Hm... It says it can be called from either rtw_cmd_thread() function > (the rtl8723bs or rtl8188eu version) which is not ideal. But also > basically harmless so whatever... > > regards, > dan carpenter > Nice tool, thanks. I'll surely use it when it is needed to find out which callers use a function pointer. However I cannot see how it can help in this context. That function *does* something, even if I cannot understand why someone needs a function to test the initialization of a pointer. Furthermore it is actually called by rtw_cmd_thread() (as you found out by using smatch) that expect one of the two possible values that led_blink_hdl() returns. That said, what trick could I use for the purpose of getting rid of that function? At this point I'm not sure it could be made. Regards, Fabio