Re: [PATCH] ALSA: control led: fix memory leak in snd_ctl_led_register
From: Dan Carpenter
Date: Mon May 31 2021 - 07:08:42 EST
I've also created a Smatch check for missing ->release() functions. It
find one bug in that file. There are other bugs, but the static checker
is not clever enough to find them. I expect Smatch will get smarter
about this in the coming year.
sound/core/control_led.c:685 snd_ctl_led_sysfs_add() warn: calling put_device() with no ->release() function
So, yeay, I feel like this thread has been useful and I now understand
put_device() a little better. Please review the email thread again and
send a v2 patch. :)
regards,
dan carpenter
/*
* Copyright (C) 2021 Oracle.
*
* 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"
#include "smatch_extra.h"
static int my_id;
static void match_put_device(struct expression *expr, const char *name, struct symbol *sym, void *data)
{
struct smatch_state *state;
state = get_state(SMATCH_EXTRA, name, sym);
if (!state ||
estate_min(state).value != 0 ||
estate_max(state).value != 0)
return;
sm_warning("calling put_device() with no ->release() function");
}
void check_no_release(int id)
{
my_id = id;
if (option_project != PROJ_KERNEL)
return;
add_function_param_key_hook("put_device", &match_put_device, 0, "$->release", NULL);
add_function_param_key_hook("device_unregister", &match_put_device, 0, "$->release", NULL);
}