On Fri, Feb 07, 2025 at 05:37:22PM +0200, Laurent Pinchart wrote: > I'm tempted to then rename of_find_node_by_name() to > __of_find_node_by_name() to indicate it's an internal function not meant > to be called except in special cases. It could all be renamed to > __of_find_next_node_by_name() to make its behaviour clearer. > Adding "next" to the name would help a lot. Joe Hattori was finding some of these bugs using his static checker. We could easily write something really specific to find this sort of bug using Smatch. If you have ideas like this feel free to ask on smatch@xxxxxxxxxxxxxxx. It doesn't find anything that your grep didn't find but any new bugs will be detected when they're introduced. regards, dan carpenter
drivers/net/ethernet/broadcom/asp2/bcmasp.c:1370 bcmasp_probe() warn: 'dev->of_node' was not incremented drivers/net/pse-pd/tps23881.c:505 tps23881_get_of_channels() warn: 'priv->np' was not incremented drivers/media/platform/qcom/venus/core.c:301 venus_add_video_core() warn: 'dev->of_node' was not incremented drivers/regulator/tps6594-regulator.c:618 tps6594_regulator_probe() warn: 'tps->dev->of_node' was not incremented
/* * Copyright 2025 Linaro Ltd. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt */ #include "smatch.h" static int my_id; static void of_find_node_by_name(struct expression *expr, const char *name, struct symbol *sym, void *data) { if (!refcount_was_inced_name_sym(name, sym, "->kobj.kref.refcount.refs.counter")) sm_warning("'%s' was not incremented", name); } void check_of_find_node_by_name(int id) { my_id = id; if (option_project != PROJ_KERNEL) return; add_function_param_key_hook_early("of_find_node_by_name", &of_find_node_by_name, 0, "$", NULL); }