mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-18 09:44:18 +08:00
e992ef5705
When the kernel is running in secure boot mode, we lock down the kernel to prevent userspace from modifying the running kernel image. Whilst this includes prohibiting access to things like /dev/mem, it must also prevent access by means of configuring driver modules in such a way as to cause a device to access or modify the kernel image. To this end, annotate module_param* statements that refer to hardware configuration and indicate for future reference what type of parameter they specify. The parameter parser in the core sees this information and can skip such parameters with an error message if the kernel is locked down. The module initialisation then runs as normal, but just sees whatever the default values for those parameters is. Note that we do still need to do the module initialisation because some drivers have viable defaults set in case parameters aren't specified and some drivers support automatic configuration (e.g. PNP or PCI) in addition to manually coded parameters. This patch annotates drivers in sound/isa/. Suggested-by: Alan Cox <gnomes@lxorguk.ukuu.org.uk> Signed-off-by: David Howells <dhowells@redhat.com> cc: Jaroslav Kysela <perex@perex.cz> cc: Takashi Iwai <tiwai@suse.com> cc: alsa-devel@alsa-project.org
116 lines
2.6 KiB
C
116 lines
2.6 KiB
C
/*
|
|
* AdLib FM card driver.
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/isa.h>
|
|
#include <sound/core.h>
|
|
#include <sound/initval.h>
|
|
#include <sound/opl3.h>
|
|
|
|
#define CRD_NAME "AdLib FM"
|
|
#define DEV_NAME "adlib"
|
|
|
|
MODULE_DESCRIPTION(CRD_NAME);
|
|
MODULE_AUTHOR("Rene Herman");
|
|
MODULE_LICENSE("GPL");
|
|
|
|
static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
|
|
static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
|
|
static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;
|
|
static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
|
|
|
|
module_param_array(index, int, NULL, 0444);
|
|
MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
|
|
module_param_array(id, charp, NULL, 0444);
|
|
MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
|
|
module_param_array(enable, bool, NULL, 0444);
|
|
MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
|
|
module_param_hw_array(port, long, ioport, NULL, 0444);
|
|
MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
|
|
|
|
static int snd_adlib_match(struct device *dev, unsigned int n)
|
|
{
|
|
if (!enable[n])
|
|
return 0;
|
|
|
|
if (port[n] == SNDRV_AUTO_PORT) {
|
|
dev_err(dev, "please specify port\n");
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
static void snd_adlib_free(struct snd_card *card)
|
|
{
|
|
release_and_free_resource(card->private_data);
|
|
}
|
|
|
|
static int snd_adlib_probe(struct device *dev, unsigned int n)
|
|
{
|
|
struct snd_card *card;
|
|
struct snd_opl3 *opl3;
|
|
int error;
|
|
|
|
error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
|
|
if (error < 0) {
|
|
dev_err(dev, "could not create card\n");
|
|
return error;
|
|
}
|
|
|
|
card->private_data = request_region(port[n], 4, CRD_NAME);
|
|
if (!card->private_data) {
|
|
dev_err(dev, "could not grab ports\n");
|
|
error = -EBUSY;
|
|
goto out;
|
|
}
|
|
card->private_free = snd_adlib_free;
|
|
|
|
strcpy(card->driver, DEV_NAME);
|
|
strcpy(card->shortname, CRD_NAME);
|
|
sprintf(card->longname, CRD_NAME " at %#lx", port[n]);
|
|
|
|
error = snd_opl3_create(card, port[n], port[n] + 2, OPL3_HW_AUTO, 1, &opl3);
|
|
if (error < 0) {
|
|
dev_err(dev, "could not create OPL\n");
|
|
goto out;
|
|
}
|
|
|
|
error = snd_opl3_hwdep_new(opl3, 0, 0, NULL);
|
|
if (error < 0) {
|
|
dev_err(dev, "could not create FM\n");
|
|
goto out;
|
|
}
|
|
|
|
error = snd_card_register(card);
|
|
if (error < 0) {
|
|
dev_err(dev, "could not register card\n");
|
|
goto out;
|
|
}
|
|
|
|
dev_set_drvdata(dev, card);
|
|
return 0;
|
|
|
|
out: snd_card_free(card);
|
|
return error;
|
|
}
|
|
|
|
static int snd_adlib_remove(struct device *dev, unsigned int n)
|
|
{
|
|
snd_card_free(dev_get_drvdata(dev));
|
|
return 0;
|
|
}
|
|
|
|
static struct isa_driver snd_adlib_driver = {
|
|
.match = snd_adlib_match,
|
|
.probe = snd_adlib_probe,
|
|
.remove = snd_adlib_remove,
|
|
|
|
.driver = {
|
|
.name = DEV_NAME
|
|
}
|
|
};
|
|
|
|
module_isa_driver(snd_adlib_driver, SNDRV_CARDS);
|