]> git.neil.brown.name Git - history.git/commitdiff
[PATCH] sound/* strncpy conversion
authorBen Collins <bcollins@debian.org>
Sun, 25 May 2003 09:19:48 +0000 (02:19 -0700)
committerLinus Torvalds <torvalds@home.transmeta.com>
Sun, 25 May 2003 09:19:48 +0000 (02:19 -0700)
This does a lot of cleanup for strncpy->strlcpy, replaces some
sprintf/snprintf's aswell.  There were only two places where things
weren't straight forward.  All-in-all a good cleanup though.

37 files changed:
sound/core/control.c
sound/core/hwdep.c
sound/core/init.c
sound/core/oss/mixer_oss.c
sound/core/pcm.c
sound/core/pcm_native.c
sound/core/rawmidi.c
sound/core/seq/oss/seq_oss_midi.c
sound/core/seq/oss/seq_oss_synth.c
sound/core/seq/seq_clientmgr.c
sound/core/seq/seq_device.c
sound/core/seq/seq_instr.c
sound/core/seq/seq_ports.c
sound/core/timer.c
sound/drivers/opl3/opl3_oss.c
sound/i2c/i2c.c
sound/isa/ad1848/ad1848_lib.c
sound/isa/sb/sb16_csp.c
sound/isa/sb/sb_mixer.c
sound/oss/ac97_codec.c
sound/oss/btaudio.c
sound/oss/cmpci.c
sound/oss/cs4281/cs4281m.c
sound/oss/dev_table.c
sound/oss/dmasound/dmasound_core.c
sound/oss/emu10k1/mixer.c
sound/oss/es1370.c
sound/oss/esssolo1.c
sound/oss/gus_wave.c
sound/oss/maestro.c
sound/oss/msnd_pinnacle.c
sound/oss/sequencer.c
sound/oss/sonicvibes.c
sound/oss/soundcard.c
sound/pci/emu10k1/emufx.c
sound/usb/usbaudio.c
sound/usb/usbmixer.c

index c01a2ce81cd38ae25ce62fd0792e86d633462f61..14541cd122f52a3a41e048d97b40c111cf011e92 100644 (file)
@@ -222,7 +222,7 @@ snd_kcontrol_t *snd_ctl_new1(snd_kcontrol_new_t * ncontrol, void *private_data)
        kctl.id.device = ncontrol->device;
        kctl.id.subdevice = ncontrol->subdevice;
        if (ncontrol->name)
-               strncpy(kctl.id.name, ncontrol->name, sizeof(kctl.id.name)-1);
+               strlcpy(kctl.id.name, ncontrol->name, sizeof(kctl.id.name));
        kctl.id.index = ncontrol->index;
        kctl.count = ncontrol->count ? ncontrol->count : 1;
        access = ncontrol->access == 0 ? SNDRV_CTL_ELEM_ACCESS_READWRITE :
@@ -449,12 +449,12 @@ static int snd_ctl_card_info(snd_card_t * card, snd_ctl_file_t * ctl,
        memset(&info, 0, sizeof(info));
        down_read(&snd_ioctl_rwsem);
        info.card = card->number;
-       strncpy(info.id, card->id, sizeof(info.id) - 1);
-       strncpy(info.driver, card->driver, sizeof(info.driver) - 1);
-       strncpy(info.name, card->shortname, sizeof(info.name) - 1);
-       strncpy(info.longname, card->longname, sizeof(info.longname) - 1);
-       strncpy(info.mixername, card->mixername, sizeof(info.mixername) - 1);
-       strncpy(info.components, card->components, sizeof(info.components) - 1);
+       strlcpy(info.id, card->id, sizeof(info.id));
+       strlcpy(info.driver, card->driver, sizeof(info.driver));
+       strlcpy(info.name, card->shortname, sizeof(info.name));
+       strlcpy(info.longname, card->longname, sizeof(info.longname));
+       strlcpy(info.mixername, card->mixername, sizeof(info.mixername));
+       strlcpy(info.components, card->components, sizeof(info.components));
        up_read(&snd_ioctl_rwsem);
        if (copy_to_user((void *) arg, &info, sizeof(snd_ctl_card_info_t)))
                return -EFAULT;
index 2f9dbfaffdf8e1cb2aafc4ac4e8e88e5a1fe8d83..94f7feffabed3b0c872b2f297a252f885b60b7d7 100644 (file)
@@ -169,8 +169,8 @@ static int snd_hwdep_info(snd_hwdep_t *hw, snd_hwdep_info_t *_info)
        
        memset(&info, 0, sizeof(info));
        info.card = hw->card->number;
-       strncpy(info.id, hw->id, sizeof(info.id) - 1);  
-       strncpy(info.name, hw->name, sizeof(info.name) - 1);
+       strlcpy(info.id, hw->id, sizeof(info.id));      
+       strlcpy(info.name, hw->name, sizeof(info.name));
        info.iface = hw->iface;
        if (copy_to_user(_info, &info, sizeof(info)))
                return -EFAULT;
@@ -343,7 +343,7 @@ int snd_hwdep_new(snd_card_t * card, char *id, int device, snd_hwdep_t ** rhwdep
        hwdep->card = card;
        hwdep->device = device;
        if (id) {
-               strncpy(hwdep->id, id, sizeof(hwdep->id) - 1);
+               strlcpy(hwdep->id, id, sizeof(hwdep->id));
        }
 #ifdef CONFIG_SND_OSSEMUL
        hwdep->oss_type = -1;
index 5a45b82f499308180913b6c4407059d1d9568ef3..e34e8480f1c7bb5b65f103c17c861c0ece28a6ab 100644 (file)
@@ -76,7 +76,7 @@ snd_card_t *snd_card_new(int idx, const char *xid,
        if (xid) {
                if (!snd_info_check_reserved_words(xid))
                        goto __error;
-               strncpy(card->id, xid, sizeof(card->id) - 1);
+               strlcpy(card->id, xid, sizeof(card->id));
        }
        write_lock(&snd_card_rwlock);
        if (idx < 0) {
index c01b1fffad65d9df7ab1f56b8ecf7cbbaf719d4b..cd1dd357d29240514e72f0df42976d3164fbdad3 100644 (file)
@@ -85,8 +85,8 @@ static int snd_mixer_oss_info(snd_mixer_oss_file_t *fmixer,
        struct mixer_info info;
        
        memset(&info, 0, sizeof(info));
-       strncpy(info.id, mixer && mixer->id[0] ? mixer->id : card->driver, sizeof(info.id) - 1);
-       strncpy(info.name, mixer && mixer->name[0] ? mixer->name : card->mixername, sizeof(info.name) - 1);
+       strlcpy(info.id, mixer && mixer->id[0] ? mixer->id : card->driver, sizeof(info.id));
+       strlcpy(info.name, mixer && mixer->name[0] ? mixer->name : card->mixername, sizeof(info.name));
        info.modify_counter = card->mixer_oss_change_count;
        if (copy_to_user(_info, &info, sizeof(info)))
                return -EFAULT;
@@ -101,8 +101,8 @@ static int snd_mixer_oss_info_obsolete(snd_mixer_oss_file_t *fmixer,
        _old_mixer_info info;
        
        memset(&info, 0, sizeof(info));
-       strncpy(info.id, mixer && mixer->id[0] ? mixer->id : card->driver, sizeof(info.id) - 1);
-       strncpy(info.name, mixer && mixer->name[0] ? mixer->name : card->mixername, sizeof(info.name) - 1);
+       strlcpy(info.id, mixer && mixer->id[0] ? mixer->id : card->driver, sizeof(info.id));
+       strlcpy(info.name, mixer && mixer->name[0] ? mixer->name : card->mixername, sizeof(info.name));
        if (copy_to_user(_info, &info, sizeof(info)))
                return -EFAULT;
        return 0;
@@ -1215,11 +1215,10 @@ static int snd_mixer_oss_notify_handler(snd_card_t * card, int cmd)
                }
                mixer->oss_dev_alloc = 1;
                mixer->card = card;
-               if (*card->mixername) {
-                       strncpy(mixer->name, card->mixername, sizeof(mixer->name) - 1);
-                       mixer->name[sizeof(mixer->name)-1] = 0;
-               } else
-                       strcpy(mixer->name, name);
+               if (*card->mixername)
+                       strlcpy(mixer->name, card->mixername, sizeof(mixer->name));
+               else
+                       strlcpy(mixer->name, name, sizeof(mixer->name));
 #ifdef SNDRV_OSS_INFO_DEV_MIXERS
                snd_oss_info_register(SNDRV_OSS_INFO_DEV_MIXERS,
                                      card->number,
index 427e6f5de9d12e5434345df5ade778d48690cb5c..a494f3c1eb62128144d42094dfbba5185fb3eae9 100644 (file)
@@ -639,7 +639,7 @@ int snd_pcm_new(snd_card_t * card, char *id, int device,
        pcm->card = card;
        pcm->device = device;
        if (id) {
-               strncpy(pcm->id, id, sizeof(pcm->id) - 1);
+               strlcpy(pcm->id, id, sizeof(pcm->id));
        }
        if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count)) < 0) {
                snd_pcm_free(pcm);
index 4b3fab10f1e5f32b34219a8bf61938acf7fb16ec..c1f9a5041aa9d4be190aebe0d1286639bb1f9a68 100644 (file)
@@ -92,13 +92,13 @@ int snd_pcm_info(snd_pcm_substream_t * substream, snd_pcm_info_t *info)
        info->device = pcm->device;
        info->stream = substream->stream;
        info->subdevice = substream->number;
-       strncpy(info->id, pcm->id, sizeof(info->id)-1);
-       strncpy(info->name, pcm->name, sizeof(info->name)-1);
+       strlcpy(info->id, pcm->id, sizeof(info->id));
+       strlcpy(info->name, pcm->name, sizeof(info->name));
        info->dev_class = pcm->dev_class;
        info->dev_subclass = pcm->dev_subclass;
        info->subdevices_count = pstr->substream_count;
        info->subdevices_avail = pstr->substream_count - pstr->substream_opened;
-       strncpy(info->subname, substream->name, sizeof(info->subname)-1);
+       strlcpy(info->subname, substream->name, sizeof(info->subname));
        runtime = substream->runtime;
        /* AB: FIXME!!! This is definitely nonsense */
        if (runtime) {
index 8285d83f4b0f0ed44a114e7ff6c4c354b6f8451b..7071db9665062cb198a72ff2a452c33ca7e30330 100644 (file)
@@ -1394,7 +1394,7 @@ int snd_rawmidi_new(snd_card_t * card, char *id, int device,
        init_MUTEX(&rmidi->open_mutex);
        init_waitqueue_head(&rmidi->open_wait);
        if (id != NULL)
-               strncpy(rmidi->id, id, sizeof(rmidi->id) - 1);
+               strlcpy(rmidi->id, id, sizeof(rmidi->id));
        if ((err = snd_rawmidi_alloc_substreams(rmidi, &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT], SNDRV_RAWMIDI_STREAM_INPUT, input_count)) < 0) {
                snd_rawmidi_free(rmidi);
                return err;
index 599d0c71d3b45111768f1733c4ad12e0b2024d94..17d8712cf4a9f8cd7f1d6e78c68707018f0af724 100644 (file)
@@ -184,8 +184,7 @@ snd_seq_oss_midi_check_new_port(snd_seq_port_info_t *pinfo)
        snd_use_lock_init(&mdev->use_lock);
 
        /* copy and truncate the name of synth device */
-       strncpy(mdev->name, pinfo->name, sizeof(mdev->name));
-       mdev->name[sizeof(mdev->name) - 1] = 0;
+       strlcpy(mdev->name, pinfo->name, sizeof(mdev->name));
 
        /* create MIDI coder */
        if (snd_midi_event_new(MAX_MIDI_EVENT_BUF, &mdev->coder) < 0) {
@@ -659,7 +658,7 @@ snd_seq_oss_midi_make_info(seq_oss_devinfo_t *dp, int dev, struct midi_info *inf
        inf->device = dev;
        inf->dev_type = 0; /* FIXME: ?? */
        inf->capabilities = 0; /* FIXME: ?? */
-       strncpy(inf->name, mdev->name, sizeof(inf->name));
+       strlcpy(inf->name, mdev->name, sizeof(inf->name));
        snd_use_lock_free(&mdev->use_lock);
        return 0;
 }
index a8bc4a7b999dc60622d80a88733bb7d8405c8de7..bbc7cb8dda1109f3acb0ca6d26865f442c4a8aa8 100644 (file)
@@ -117,8 +117,7 @@ snd_seq_oss_synth_register(snd_seq_device_t *dev)
        snd_use_lock_init(&rec->use_lock);
 
        /* copy and truncate the name of synth device */
-       strncpy(rec->name, dev->name, sizeof(rec->name));
-       rec->name[sizeof(rec->name)-1] = 0;
+       strlcpy(rec->name, dev->name, sizeof(rec->name));
 
        /* registration */
        spin_lock_irqsave(&register_lock, flags);
@@ -611,7 +610,7 @@ snd_seq_oss_synth_make_info(seq_oss_devinfo_t *dp, int dev, struct synth_info *i
                inf->synth_subtype = 0;
                inf->nr_voices = 16;
                inf->device = dev;
-               strncpy(inf->name, minf.name, sizeof(inf->name));
+               strlcpy(inf->name, minf.name, sizeof(inf->name));
        } else {
                if ((rec = get_synthdev(dp, dev)) == NULL)
                        return -ENXIO;
@@ -619,7 +618,7 @@ snd_seq_oss_synth_make_info(seq_oss_devinfo_t *dp, int dev, struct synth_info *i
                inf->synth_subtype = rec->synth_subtype;
                inf->nr_voices = rec->nr_voices;
                inf->device = dev;
-               strncpy(inf->name, rec->name, sizeof(inf->name));
+               strlcpy(inf->name, rec->name, sizeof(inf->name));
                snd_use_lock_free(&rec->use_lock);
        }
        return 0;
index 6be15ff87c7b5b028a77ddc192c90453cbe232c9..7f39dfc9d2cbdbc8d098e94cabfc164e9ba44dc7 100644 (file)
@@ -1184,10 +1184,9 @@ static int snd_seq_ioctl_set_client_info(client_t * client, void __user *arg)
                return -EINVAL;
 
        /* fill the info fields */
-       if (client_info.name[0]) {
-               strncpy(client->name, client_info.name, sizeof(client->name)-1);
-               client->name[sizeof(client->name)-1] = '\0';
-       }
+       if (client_info.name[0])
+               strlcpy(client->name, client_info.name, sizeof(client->name));
+
        client->filter = client_info.filter;
        client->event_lost = client_info.event_lost;
        memcpy(client->event_filter, client_info.event_filter, 32);
@@ -1487,9 +1486,8 @@ static int snd_seq_ioctl_create_queue(client_t *client, void __user *arg)
 
        /* set queue name */
        if (! info.name[0])
-               sprintf(info.name, "Queue-%d", q->queue);
-       strncpy(q->name, info.name, sizeof(q->name)-1);
-       q->name[sizeof(q->name)-1] = 0;
+               snprintf(info.name, sizeof(info.name), "Queue-%d", q->queue);
+       strlcpy(q->name, info.name, sizeof(q->name));
        queuefree(q);
 
        if (copy_to_user(arg, &info, sizeof(info)))
@@ -1526,8 +1524,7 @@ static int snd_seq_ioctl_get_queue_info(client_t *client, void __user *arg)
        info.queue = q->queue;
        info.owner = q->owner;
        info.locked = q->locked;
-       strncpy(info.name, q->name, sizeof(info.name) - 1);
-       info.name[sizeof(info.name)-1] = 0;
+       strlcpy(info.name, q->name, sizeof(info.name));
        queuefree(q);
 
        if (copy_to_user(arg, &info, sizeof(info)))
@@ -1565,8 +1562,7 @@ static int snd_seq_ioctl_set_queue_info(client_t *client, void __user *arg)
                queuefree(q);
                return -EPERM;
        }
-       strncpy(q->name, info.name, sizeof(q->name) - 1);
-       q->name[sizeof(q->name)-1] = 0;
+       strlcpy(q->name, info.name, sizeof(q->name));
        queuefree(q);
 
        return 0;
index 64ccb69b48653aa382f0834d0adec5e28463719e..297f918522e8bb82f8dbf8a01ba472b4559097b7 100644 (file)
@@ -187,8 +187,7 @@ int snd_seq_device_new(snd_card_t *card, int device, char *id, int argsize,
        /* set up device info */
        dev->card = card;
        dev->device = device;
-       strncpy(dev->id, id, sizeof(dev->id) - 1);
-       dev->id[sizeof(dev->id) - 1] = 0;
+       strlcpy(dev->id, id, sizeof(dev->id));
        dev->argsize = argsize;
        dev->status = SNDRV_SEQ_DEVICE_FREE;
 
@@ -350,8 +349,7 @@ static ops_list_t * create_driver(char *id)
        memset(ops, 0, sizeof(*ops));
 
        /* set up driver entry */
-       strncpy(ops->id, id, sizeof(ops->id) - 1);
-       ops->id[sizeof(ops->id) - 1] = 0;
+       strlcpy(ops->id, id, sizeof(ops->id));
        init_MUTEX(&ops->reg_mutex);
        ops->driver = DRIVER_EMPTY;
        INIT_LIST_HEAD(&ops->dev_list);
index 97e5b740816d97467389e5cf41da743853af7b58..d8ca16f6f29329c40d6633d99dd7d82176505ad2 100644 (file)
@@ -478,8 +478,7 @@ static int instr_put(snd_seq_kinstr_ops_t *ops,
        }
        instr->ops = ops;
        instr->instr = put.id.instr;
-       strncpy(instr->name, put.data.name, sizeof(instr->name)-1);
-       instr->name[sizeof(instr->name)-1] = '\0';
+       strlcpy(instr->name, put.data.name, sizeof(instr->name));
        instr->type = put.data.type;
        if (instr->type == SNDRV_SEQ_INSTR_ATYPE_DATA) {
                result = ops->put(ops->private_data,
index 2988ba6c5691c6becef7af7ea59e78e54bf9bace..9167e164d5924aa6587c84ca37b42be15c2cea46 100644 (file)
@@ -338,10 +338,8 @@ int snd_seq_set_port_info(client_port_t * port, snd_seq_port_info_t * info)
        snd_assert(port && info, return -EINVAL);
 
        /* set port name */
-       if (info->name[0]) {
-               strncpy(port->name, info->name, sizeof(port->name)-1);
-               port->name[sizeof(port->name)-1] = '\0';
-       }
+       if (info->name[0])
+               strlcpy(port->name, info->name, sizeof(port->name));
        
        /* set capabilities */
        port->capability = info->capability;
@@ -363,7 +361,7 @@ int snd_seq_get_port_info(client_port_t * port, snd_seq_port_info_t * info)
        snd_assert(port && info, return -EINVAL);
 
        /* get port name */
-       strncpy(info->name, port->name, sizeof(info->name));
+       strlcpy(info->name, port->name, sizeof(info->name));
        
        /* get capabilities */
        info->capability = port->capability;
@@ -621,10 +619,8 @@ int snd_seq_event_port_attach(int client,
        /* Set up the port */
        memset(&portinfo, 0, sizeof(portinfo));
        portinfo.addr.client = client;
-       if (portname)
-               strncpy(portinfo.name, portname, sizeof(portinfo.name));
-       else
-               sprintf(portinfo.name, "Unamed port");
+       strlcpy(portinfo.name, portname ? portname : "Unamed port",
+               sizeof(portinfo.name));
 
        portinfo.capability = cap;
        portinfo.type = type;
index c426c77e45c31db8d37f09b3b08d0ae87dfdd9a4..1a2f9285ccdbde420a139e303abdd2ee5bd3eef2 100644 (file)
@@ -749,7 +749,7 @@ int snd_timer_new(snd_card_t *card, char *id, snd_timer_id_t *tid, snd_timer_t *
        timer->tmr_device = tid->device;
        timer->tmr_subdevice = tid->subdevice;
        if (id)
-               strncpy(timer->id, id, sizeof(timer->id) - 1);
+               strlcpy(timer->id, id, sizeof(timer->id));
        INIT_LIST_HEAD(&timer->device_list);
        INIT_LIST_HEAD(&timer->open_list_head);
        INIT_LIST_HEAD(&timer->active_list_head);
@@ -1317,8 +1317,8 @@ static int snd_timer_user_ginfo(struct file *file, snd_timer_ginfo_t *_ginfo)
                ginfo.card = t->card ? t->card->number : -1;
                if (t->hw.flags & SNDRV_TIMER_HW_SLAVE)
                        ginfo.flags |= SNDRV_TIMER_FLG_SLAVE;
-               strncpy(ginfo.id, t->id, sizeof(ginfo.id)-1);
-               strncpy(ginfo.name, t->name, sizeof(ginfo.name)-1);
+               strlcpy(ginfo.id, t->id, sizeof(ginfo.id));
+               strlcpy(ginfo.name, t->name, sizeof(ginfo.name));
                ginfo.resolution = t->hw.resolution;
                if (t->hw.resolution_min > 0) {
                        ginfo.resolution_min = t->hw.resolution_min;
@@ -1457,8 +1457,8 @@ static int snd_timer_user_info(struct file *file, snd_timer_info_t *_info)
        info.card = t->card ? t->card->number : -1;
        if (t->hw.flags & SNDRV_TIMER_HW_SLAVE)
                info.flags |= SNDRV_TIMER_FLG_SLAVE;
-       strncpy(info.id, t->id, sizeof(info.id)-1);
-       strncpy(info.name, t->name, sizeof(info.name)-1);
+       strlcpy(info.id, t->id, sizeof(info.id));
+       strlcpy(info.name, t->name, sizeof(info.name));
        info.resolution = t->hw.resolution;
        if (copy_to_user(_info, &info, sizeof(*_info)))
                return -EFAULT;
index 80c6545d72fdc5dd34c1521eb27aa636ad7f2e7b..5504605adc74201858c89fdf2831dbf9ad2c72cc 100644 (file)
@@ -123,8 +123,7 @@ void snd_opl3_init_seq_oss(opl3_t *opl3, char *name)
                return;
 
        opl3->oss_seq_dev = dev;
-       strncpy(dev->name, name, sizeof(dev->name) - 1);
-       dev->name[sizeof(dev->name) - 1] = 0;
+       strlcpy(dev->name, name, sizeof(dev->name));
        arg = SNDRV_SEQ_DEVICE_ARGPTR(dev);
        arg->type = SYNTH_TYPE_FM;
        if (opl3->hardware < OPL3_HW_OPL3) {
index 5015a8bc8c0d5d2d29c5bb09cfb0790631ab3438..cdb9c74adc5c0b7b40c87189a80a6b99ce783be2 100644 (file)
@@ -93,7 +93,7 @@ int snd_i2c_bus_create(snd_card_t *card, const char *name, snd_i2c_bus_t *master
                list_add_tail(&bus->buses, &master->buses);
                bus->master = master;
        }
-       strncpy(bus->name, name, sizeof(bus->name) - 1);
+       strlcpy(bus->name, name, sizeof(bus->name));
        if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, bus, &ops)) < 0) {
                snd_i2c_bus_free(bus);
                return err;
@@ -112,7 +112,7 @@ int snd_i2c_device_create(snd_i2c_bus_t *bus, const char *name, unsigned char ad
        if (device == NULL)
                return -ENOMEM;
        device->addr = addr;
-       strncpy(device->name, name, sizeof(device->name)-1);
+       strlcpy(device->name, name, sizeof(device->name));
        list_add_tail(&device->list, &bus->devices);
        device->bus = bus;
        *rdevice = device;
index 1ea965fbc635fb6a22ae789c21bc19d7892a2a66..125fd3507ce5564417e9e0996592923b5e19c048 100644 (file)
@@ -1148,7 +1148,7 @@ int snd_ad1848_add_ctl(ad1848_t *chip, const char *name, int index, int type, un
        ctl = snd_ctl_new1(&newctls[type], chip);
        if (! ctl)
                return -ENOMEM;
-       strncpy(ctl->id.name, name, sizeof(ctl->id.name)-1);
+       strlcpy(ctl->id.name, name, sizeof(ctl->id.name));
        ctl->id.index = index;
        ctl->private_value = value;
        if ((err = snd_ctl_add(chip->card, ctl)) < 0) {
index 8ea3dae9d802acaed2de1c805a15292c515e641b..524e43db882a83bdd837b8e16cd6d753e9b5eea4 100644 (file)
@@ -393,8 +393,7 @@ static int snd_sb_csp_riff_load(snd_sb_csp_t * p, snd_sb_csp_microcode_t * mcode
                                return err;
 
                        /* fill in codec header */
-                       strncpy(p->codec_name, info.codec_name, sizeof(p->codec_name) - 1);
-                       p->codec_name[sizeof(p->codec_name) - 1] = 0;
+                       strlcpy(p->codec_name, info.codec_name, sizeof(p->codec_name));
                        p->func_nr = func_nr;
                        p->mode = LE_SHORT(funcdesc_h.flags_play_rec);
                        switch (LE_SHORT(funcdesc_h.VOC_type)) {
index b5532d9e19da4b3edc262ac4ba16b7dce3b6fff6..31baf2030e26b8b35f927edad151bc363c0cc840 100644 (file)
@@ -452,7 +452,7 @@ int snd_sbmixer_add_ctl(sb_t *chip, const char *name, int index, int type, unsig
        ctl = snd_ctl_new1(&newctls[type], chip);
        if (! ctl)
                return -ENOMEM;
-       strncpy(ctl->id.name, name, sizeof(ctl->id.name)-1);
+       strlcpy(ctl->id.name, name, sizeof(ctl->id.name));
        ctl->id.index = index;
        ctl->private_value = value;
        if ((err = snd_ctl_add(chip->card, ctl)) < 0) {
index 7eaad4f5c9ce41971ba506421402e42015b7f650..be1820ea876fd7e4f16be1df9513a9941eb5f4ad 100644 (file)
@@ -487,8 +487,8 @@ static int ac97_mixer_ioctl(struct ac97_codec *codec, unsigned int cmd, unsigned
 
        if (cmd == SOUND_MIXER_INFO) {
                mixer_info info;
-               strncpy(info.id, codec->name, sizeof(info.id));
-               strncpy(info.name, codec->name, sizeof(info.name));
+               strlcpy(info.id, codec->name, sizeof(info.id));
+               strlcpy(info.name, codec->name, sizeof(info.name));
                info.modify_counter = codec->modcnt;
                if (copy_to_user((void *)arg, &info, sizeof(info)))
                        return -EFAULT;
@@ -496,8 +496,8 @@ static int ac97_mixer_ioctl(struct ac97_codec *codec, unsigned int cmd, unsigned
        }
        if (cmd == SOUND_OLD_MIXER_INFO) {
                _old_mixer_info info;
-               strncpy(info.id, codec->name, sizeof(info.id));
-               strncpy(info.name, codec->name, sizeof(info.name));
+               strlcpy(info.id, codec->name, sizeof(info.id));
+               strlcpy(info.name, codec->name, sizeof(info.name));
                if (copy_to_user((void *)arg, &info, sizeof(info)))
                        return -EFAULT;
                return 0;
index 0585b44d67b52261700f4c2a3b995e7c903dde5f..22e3b6cfd81799095bf93b4aebf0c7a77fba81b3 100644 (file)
@@ -328,8 +328,8 @@ static int btaudio_mixer_ioctl(struct inode *inode, struct file *file,
        if (cmd == SOUND_MIXER_INFO) {
                mixer_info info;
                memset(&info,0,sizeof(info));
-                strncpy(info.id,"bt878",sizeof(info.id)-1);
-                strncpy(info.name,"Brooktree Bt878 audio",sizeof(info.name)-1);
+                strlcpy(info.id,"bt878",sizeof(info.id));
+                strlcpy(info.name,"Brooktree Bt878 audio",sizeof(info.name));
                 info.modify_counter = bta->mixcount;
                 if (copy_to_user((void *)arg, &info, sizeof(info)))
                         return -EFAULT;
@@ -338,8 +338,8 @@ static int btaudio_mixer_ioctl(struct inode *inode, struct file *file,
        if (cmd == SOUND_OLD_MIXER_INFO) {
                _old_mixer_info info;
                memset(&info,0,sizeof(info));
-                strncpy(info.id,"bt878",sizeof(info.id)-1);
-                strncpy(info.name,"Brooktree Bt878 audio",sizeof(info.name)-1);
+                strlcpy(info.id,"bt878",sizeof(info.id)-1);
+                strlcpy(info.name,"Brooktree Bt878 audio",sizeof(info.name));
                 if (copy_to_user((void *)arg, &info, sizeof(info)))
                         return -EFAULT;
                return 0;
index 967b6521b80320c2d731139490011d306789c61e..f9d7842316353cb54aa0db10cbe478e8e41509dc 100644 (file)
@@ -1268,8 +1268,8 @@ static int mixer_ioctl(struct cm_state *s, unsigned int cmd, unsigned long arg)
        VALIDATE_STATE(s);
         if (cmd == SOUND_MIXER_INFO) {
                mixer_info info;
-               strncpy(info.id, "cmpci", sizeof(info.id));
-               strncpy(info.name, "C-Media PCI", sizeof(info.name));
+               strlcpy(info.id, "cmpci", sizeof(info.id));
+               strlcpy(info.name, "C-Media PCI", sizeof(info.name));
                info.modify_counter = s->mix.modcnt;
                if (copy_to_user((void *)arg, &info, sizeof(info)))
                        return -EFAULT;
@@ -1277,8 +1277,8 @@ static int mixer_ioctl(struct cm_state *s, unsigned int cmd, unsigned long arg)
        }
        if (cmd == SOUND_OLD_MIXER_INFO) {
                _old_mixer_info info;
-               strncpy(info.id, "cmpci", sizeof(info.id));
-               strncpy(info.name, "C-Media cmpci", sizeof(info.name));
+               strlcpy(info.id, "cmpci", sizeof(info.id));
+               strlcpy(info.name, "C-Media cmpci", sizeof(info.name));
                if (copy_to_user((void *)arg, &info, sizeof(info)))
                        return -EFAULT;
                return 0;
index 5757af59005452c361b16229dc1c775c4c1bec26..3d23a8006f976604222349ab441c72bf25a99b14 100644 (file)
@@ -2266,8 +2266,8 @@ static int mixer_ioctl(struct cs4281_state *s, unsigned int cmd,
        }
        if (cmd == SOUND_MIXER_INFO) {
                mixer_info info;
-               strncpy(info.id, "CS4281", sizeof(info.id));
-               strncpy(info.name, "Crystal CS4281", sizeof(info.name));
+               strlcpy(info.id, "CS4281", sizeof(info.id));
+               strlcpy(info.name, "Crystal CS4281", sizeof(info.name));
                info.modify_counter = s->mix.modcnt;
                if (copy_to_user((void *) arg, &info, sizeof(info)))
                        return -EFAULT;
@@ -2275,8 +2275,8 @@ static int mixer_ioctl(struct cs4281_state *s, unsigned int cmd,
        }
        if (cmd == SOUND_OLD_MIXER_INFO) {
                _old_mixer_info info;
-               strncpy(info.id, "CS4281", sizeof(info.id));
-               strncpy(info.name, "Crystal CS4281", sizeof(info.name));
+               strlcpy(info.id, "CS4281", sizeof(info.id));
+               strlcpy(info.name, "Crystal CS4281", sizeof(info.name));
                if (copy_to_user((void *) arg, &info, sizeof(info)))
                        return -EFAULT;
                return 0;
index 96e8fd9eef17d76588d3f27dbf0176accecc2891..4658e62d24cab9915ceec05f322b1807bc374455 100644 (file)
@@ -22,7 +22,7 @@ int sound_install_audiodrv(int vers, char *name, struct audio_driver *driver,
 {
        struct audio_driver *d;
        struct audio_operations *op;
-       int l, num;
+       int num;
 
        if (vers != AUDIO_DRIVER_VERSION || driver_size > sizeof(struct audio_driver)) {
                printk(KERN_ERR "Sound: Incompatible audio driver for %s\n", name);
@@ -58,11 +58,7 @@ int sound_install_audiodrv(int vers, char *name, struct audio_driver *driver,
        memcpy((char *) d, (char *) driver, driver_size);
 
        op->d = d;
-       l = strlen(name) + 1;
-       if (l > sizeof(op->name))
-               l = sizeof(op->name);
-       strncpy(op->name, name, l);
-       op->name[l - 1] = 0;
+       strlcpy(op->name, name, sizeof(op->name));
        op->flags = flags;
        op->format_mask = format_mask;
        op->devc = devc;
@@ -82,7 +78,6 @@ int sound_install_mixer(int vers, char *name, struct mixer_operations *driver,
        int driver_size, void *devc)
 {
        struct mixer_operations *op;
-       int l;
 
        int n = sound_alloc_mixerdev();
 
@@ -110,11 +105,7 @@ int sound_install_mixer(int vers, char *name, struct mixer_operations *driver,
        memset((char *) op, 0, sizeof(struct mixer_operations));
        memcpy((char *) op, (char *) driver, driver_size);
 
-       l = strlen(name) + 1;
-       if (l > sizeof(op->name))
-               l = sizeof(op->name);
-       strncpy(op->name, name, l);
-       op->name[l - 1] = 0;
+       strlcpy(op->name, name, sizeof(op->name));
        op->devc = devc;
 
        mixer_devs[n] = op;
index 98627ddea56fb949b696de606fd0340a048bb66f..069bd881589cf9bc4d34657edaad642373fb21fd 100644 (file)
@@ -351,9 +351,8 @@ static int mixer_ioctl(struct inode *inode, struct file *file, u_int cmd,
            case SOUND_MIXER_INFO:
                {
                    mixer_info info;
-                   strncpy(info.id, dmasound.mach.name2, sizeof(info.id));
-                   strncpy(info.name, dmasound.mach.name2, sizeof(info.name));
-                   info.name[sizeof(info.name)-1] = 0;
+                   strlcpy(info.id, dmasound.mach.name2, sizeof(info.id));
+                   strlcpy(info.name, dmasound.mach.name2, sizeof(info.name));
                    info.modify_counter = mixer.modify_counter;
                    if (copy_to_user((int *)arg, &info, sizeof(info)))
                            return -EFAULT;
index 6ca3b79430a1eb94ce15ff954bba910c964069f4..d61778e096d3aeb9104199d6ad3291c546a07538 100644 (file)
@@ -623,8 +623,8 @@ static int emu10k1_mixer_ioctl(struct inode *inode, struct file *file, unsigned
                if (cmd == SOUND_MIXER_INFO) {
                        mixer_info info;
 
-                       strncpy(info.id, card->ac97.name, sizeof(info.id));
-                       strncpy(info.name, "Creative SBLive - Emu10k1", sizeof(info.name));
+                       strlcpy(info.id, card->ac97.name, sizeof(info.id));
+                       strlcpy(info.name, "Creative SBLive - Emu10k1", sizeof(info.name));
                        info.modify_counter = card->ac97.modcnt;
 
                        if (copy_to_user((void *)arg, &info, sizeof(info)))
index 6f9aef48f5ba065e3ad1688a12f313637a985ebe..835d2170e8c9e9b05bbf5e2749484c2fefe483cf 100644 (file)
@@ -889,8 +889,8 @@ static int mixer_ioctl(struct es1370_state *s, unsigned int cmd, unsigned long a
        }
         if (cmd == SOUND_MIXER_INFO) {
                mixer_info info;
-               strncpy(info.id, "ES1370", sizeof(info.id));
-               strncpy(info.name, "Ensoniq ES1370", sizeof(info.name));
+               strlcpy(info.id, "ES1370", sizeof(info.id));
+               strlcpy(info.name, "Ensoniq ES1370", sizeof(info.name));
                info.modify_counter = s->mix.modcnt;
                if (copy_to_user((void *)arg, &info, sizeof(info)))
                        return -EFAULT;
@@ -898,8 +898,8 @@ static int mixer_ioctl(struct es1370_state *s, unsigned int cmd, unsigned long a
        }
        if (cmd == SOUND_OLD_MIXER_INFO) {
                _old_mixer_info info;
-               strncpy(info.id, "ES1370", sizeof(info.id));
-               strncpy(info.name, "Ensoniq ES1370", sizeof(info.name));
+               strlcpy(info.id, "ES1370", sizeof(info.id));
+               strlcpy(info.name, "Ensoniq ES1370", sizeof(info.name));
                if (copy_to_user((void *)arg, &info, sizeof(info)))
                        return -EFAULT;
                return 0;
index 78a6adad3d7dd0526e79a2e607f471b9b60c0411..d78a4dd797a4628a8d8a56b264121a4ce3a02c68 100644 (file)
@@ -721,8 +721,8 @@ static int mixer_ioctl(struct solo1_state *s, unsigned int cmd, unsigned long ar
        }
         if (cmd == SOUND_MIXER_INFO) {
                mixer_info info;
-               strncpy(info.id, "Solo1", sizeof(info.id));
-               strncpy(info.name, "ESS Solo1", sizeof(info.name));
+               strlcpy(info.id, "Solo1", sizeof(info.id));
+               strlcpy(info.name, "ESS Solo1", sizeof(info.name));
                info.modify_counter = s->mix.modcnt;
                if (copy_to_user((void *)arg, &info, sizeof(info)))
                        return -EFAULT;
@@ -730,8 +730,8 @@ static int mixer_ioctl(struct solo1_state *s, unsigned int cmd, unsigned long ar
        }
        if (cmd == SOUND_OLD_MIXER_INFO) {
                _old_mixer_info info;
-               strncpy(info.id, "Solo1", sizeof(info.id));
-               strncpy(info.name, "ESS Solo1", sizeof(info.name));
+               strlcpy(info.id, "Solo1", sizeof(info.id));
+               strlcpy(info.name, "ESS Solo1", sizeof(info.name));
                if (copy_to_user((void *)arg, &info, sizeof(info)))
                        return -EFAULT;
                return 0;
index 722e481379674f681c1aa186ebe69cd23b5c763e..8be49423b6d9a17096cd817b47967907b350c53c 100644 (file)
@@ -2851,7 +2851,7 @@ void __init gus_wave_init(struct address_info *hw_config)
        unsigned long flags;
        unsigned char val;
        char *model_num = "2.4";
-       char tmp[64], tmp2[64];
+       char tmp[64];
        int gus_type = 0x24;    /* 2.4 */
 
        int irq = hw_config->irq, dma = hw_config->dma, dma2 = hw_config->dma2;
@@ -2998,19 +2998,14 @@ void __init gus_wave_init(struct address_info *hw_config)
        }
 
        if (hw_config->name)
-       {
-               strncpy(tmp, hw_config->name, 45);
-               tmp[45] = 0;
-               sprintf(tmp2, "%s (%dk)", tmp, (int) gus_mem_size / 1024);
-               tmp2[sizeof(tmp2) - 1] = 0;
-       }
+               snprintf(tmp, sizeof(tmp), "%s (%dk)", hw_config->name,
+                        (int) gus_mem_size / 1024);
        else if (gus_pnp_flag)
-       {
-               sprintf(tmp2, "Gravis UltraSound PnP (%dk)",
-                       (int) gus_mem_size / 1024);
-       }
+               snprintf(tmp, sizeof(tmp), "Gravis UltraSound PnP (%dk)",
+                        (int) gus_mem_size / 1024);
        else
-               sprintf(tmp2, "Gravis UltraSound %s (%dk)", model_num, (int) gus_mem_size / 1024);
+               snprintf(tmp, sizeof(tmp), "Gravis UltraSound %s (%dk)", model_num,
+                        (int) gus_mem_size / 1024);
 
 
        samples = (struct patch_info *)vmalloc((MAX_SAMPLE + 1) * sizeof(*samples));
@@ -3019,9 +3014,8 @@ void __init gus_wave_init(struct address_info *hw_config)
                printk(KERN_WARNING "gus_init: Cant allocate memory for instrument tables\n");
                return;
        }
-       conf_printf(tmp2, hw_config);
-       tmp2[sizeof(gus_info.name) - 1] = 0;
-       strcpy(gus_info.name, tmp2);
+       conf_printf(tmp, hw_config);
+       strlcpy(gus_info.name, tmp, sizeof(gus_info.name));
 
        if ((sdev = sound_alloc_synthdev()) == -1)
                printk(KERN_WARNING "gus_init: Too many synthesizers\n");
index 013b701872455b3a1a801e639584003d831ca932..f62ad9be51e95d6ffc3e63d9853ea5d327282475 100644 (file)
@@ -2024,8 +2024,8 @@ static int mixer_ioctl(struct ess_card *card, unsigned int cmd, unsigned long ar
        VALIDATE_CARD(card);
         if (cmd == SOUND_MIXER_INFO) {
                mixer_info info;
-               strncpy(info.id, card_names[card->card_type], sizeof(info.id));
-               strncpy(info.name,card_names[card->card_type],sizeof(info.name));
+               strlcpy(info.id, card_names[card->card_type], sizeof(info.id));
+               strlcpy(info.name, card_names[card->card_type], sizeof(info.name));
                info.modify_counter = card->mix.modcnt;
                if (copy_to_user((void *)arg, &info, sizeof(info)))
                        return -EFAULT;
@@ -2033,8 +2033,8 @@ static int mixer_ioctl(struct ess_card *card, unsigned int cmd, unsigned long ar
        }
        if (cmd == SOUND_OLD_MIXER_INFO) {
                _old_mixer_info info;
-               strncpy(info.id, card_names[card->card_type], sizeof(info.id));
-               strncpy(info.name,card_names[card->card_type],sizeof(info.name));
+               strlcpy(info.id, card_names[card->card_type], sizeof(info.id));
+               strlcpy(info.name, card_names[card->card_type], sizeof(info.name));
                if (copy_to_user((void *)arg, &info, sizeof(info)))
                        return -EFAULT;
                return 0;
index 760a617ec17ab544a6e78420e72bd50041e33406..25977734cc6a5ff755dd4faa766b3359a2e368f1 100644 (file)
@@ -555,8 +555,8 @@ static unsigned long force_recsrc(unsigned long recsrc)
 }
 
 #define set_mixer_info()                                                       \
-               strncpy(info.id, "MSNDMIXER", sizeof(info.id));                 \
-               strncpy(info.name, "MultiSound Mixer", sizeof(info.name));
+               strlcpy(info.id, "MSNDMIXER", sizeof(info.id));                 \
+               strlcpy(info.name, "MultiSound Mixer", sizeof(info.name));
 
 static int mixer_ioctl(unsigned int cmd, unsigned long arg)
 {
index 8a2f0055f1aca9e15afe8d917a5806d89ac34f0b..d2031bc1243462671870aa837973afb2e1f90c02 100644 (file)
@@ -1477,7 +1477,7 @@ int sequencer_ioctl(int dev, struct file *file, unsigned int cmd, caddr_t arg)
                        if (!(synth_open_mask & (1 << dev)) && !orig_dev)
                                return -EBUSY;
                        memcpy(&inf, synth_devs[dev]->info, sizeof(inf));
-                       strncpy(inf.name, synth_devs[dev]->id, sizeof(inf.name));
+                       strlcpy(inf.name, synth_devs[dev]->id, sizeof(inf.name));
                        inf.device = dev;
                        return copy_to_user(arg, &inf, sizeof(inf))?-EFAULT:0;
 
index 975e1c42ed7868d9e5cdabab55d6264c5ab26780..5c042a70dda1a477b19d2772bed0237212497e7a 100644 (file)
@@ -1046,8 +1046,8 @@ static int mixer_ioctl(struct sv_state *s, unsigned int cmd, unsigned long arg)
        VALIDATE_STATE(s);
         if (cmd == SOUND_MIXER_INFO) {
                mixer_info info;
-               strncpy(info.id, "SonicVibes", sizeof(info.id));
-               strncpy(info.name, "S3 SonicVibes", sizeof(info.name));
+               strlcpy(info.id, "SonicVibes", sizeof(info.id));
+               strlcpy(info.name, "S3 SonicVibes", sizeof(info.name));
                info.modify_counter = s->mix.modcnt;
                if (copy_to_user((void *)arg, &info, sizeof(info)))
                        return -EFAULT;
@@ -1055,8 +1055,8 @@ static int mixer_ioctl(struct sv_state *s, unsigned int cmd, unsigned long arg)
        }
        if (cmd == SOUND_OLD_MIXER_INFO) {
                _old_mixer_info info;
-               strncpy(info.id, "SonicVibes", sizeof(info.id));
-               strncpy(info.name, "S3 SonicVibes", sizeof(info.name));
+               strlcpy(info.id, "SonicVibes", sizeof(info.id));
+               strlcpy(info.name, "S3 SonicVibes", sizeof(info.name));
                if (copy_to_user((void *)arg, &info, sizeof(info)))
                        return -EFAULT;
                return 0;
index 220a5faa8d70f0718ce74e8fdbc92b4123247c80..087f1af7c7e5099b36888a5d432842abbc372b98 100644 (file)
@@ -289,9 +289,8 @@ static int get_mixer_info(int dev, caddr_t arg)
 {
        mixer_info info;
 
-       strncpy(info.id, mixer_devs[dev]->id, sizeof(info.id));
-       strncpy(info.name, mixer_devs[dev]->name, sizeof(info.name));
-       info.name[sizeof(info.name)-1] = 0;
+       strlcpy(info.id, mixer_devs[dev]->id, sizeof(info.id));
+       strlcpy(info.name, mixer_devs[dev]->name, sizeof(info.name));
        info.modify_counter = mixer_devs[dev]->modify_counter;
        if (__copy_to_user(arg, &info,  sizeof(info)))
                return -EFAULT;
@@ -302,9 +301,8 @@ static int get_old_mixer_info(int dev, caddr_t arg)
 {
        _old_mixer_info info;
 
-       strncpy(info.id, mixer_devs[dev]->id, sizeof(info.id));
-       strncpy(info.name, mixer_devs[dev]->name, sizeof(info.name));
-       info.name[sizeof(info.name)-1] = 0;     
+       strlcpy(info.id, mixer_devs[dev]->id, sizeof(info.id));
+       strlcpy(info.name, mixer_devs[dev]->name, sizeof(info.name));
        if (copy_to_user(arg, &info,  sizeof(info)))
                return -EFAULT;
        return 0;
index 02e2ec335502eb650fc8b55e043281f5b7b67ae4..9dcc0931854810cee52a29217e268d8480e6d8dc 100644 (file)
@@ -1033,7 +1033,7 @@ static int snd_emu10k1_list_controls(emu10k1_t *emu, emu10k1_fx8010_code_t *icod
                        memset(&gctl, 0, sizeof(gctl));
                        id = &ctl->kcontrol->id;
                        gctl.id.iface = id->iface;
-                       strncpy(gctl.id.name, id->name, sizeof(gctl.id.name));
+                       strlcpy(gctl.id.name, id->name, sizeof(gctl.id.name));
                        gctl.id.index = id->index;
                        gctl.id.device = id->device;
                        gctl.id.subdevice = id->subdevice;
@@ -1063,8 +1063,7 @@ static int snd_emu10k1_icode_poke(emu10k1_t *emu, emu10k1_fx8010_code_t *icode)
        down(&emu->fx8010.lock);
        if ((err = snd_emu10k1_verify_controls(emu, icode)) < 0)
                goto __error;
-       strncpy(emu->fx8010.name, icode->name, sizeof(emu->fx8010.name)-1);
-       emu->fx8010.name[sizeof(emu->fx8010.name)-1] = '\0';
+       strlcpy(emu->fx8010.name, icode->name, sizeof(emu->fx8010.name));
        /* stop FX processor - this may be dangerous, but it's better to miss
           some samples than generate wrong ones - [jk] */
        if (emu->audigy)
@@ -1092,8 +1091,7 @@ static int snd_emu10k1_icode_peek(emu10k1_t *emu, emu10k1_fx8010_code_t *icode)
        int err;
 
        down(&emu->fx8010.lock);
-       strncpy(icode->name, emu->fx8010.name, sizeof(icode->name)-1);
-       emu->fx8010.name[sizeof(emu->fx8010.name)-1] = '\0';
+       strlcpy(icode->name, emu->fx8010.name, sizeof(icode->name));
        /* ok, do the main job */
        snd_emu10k1_gpr_peek(emu, icode);
        snd_emu10k1_tram_peek(emu, icode);
index c8d3b928e108f2c7fff68fb81dc32d342966126d..47772eb33250a9952a4cb34f5c672e070fce0cee 100644 (file)
@@ -2392,8 +2392,7 @@ static int snd_usb_audio_create(snd_card_t *card, struct usb_device *dev,
                len = 0;
        if (len <= 0) {
                if (quirk && quirk->product_name) {
-                       strncpy(card->shortname, quirk->product_name, sizeof(card->shortname) - 1);
-                       card->shortname[sizeof(card->shortname) - 1] = '\0';
+                       strlcpy(card->shortname, quirk->product_name, sizeof(card->shortname));
                } else {
                        sprintf(card->shortname, "USB Device %#04x:%#04x",
                                dev->descriptor.idVendor, dev->descriptor.idProduct);
@@ -2403,37 +2402,32 @@ static int snd_usb_audio_create(snd_card_t *card, struct usb_device *dev,
        /* retrieve the vendor and device strings as longname */
        if (dev->descriptor.iManufacturer)
                len = usb_string(dev, dev->descriptor.iManufacturer,
-                                card->longname, sizeof(card->longname) - 1);
+                                card->longname, sizeof(card->longname));
        else
                len = 0;
        if (len <= 0) {
                if (quirk && quirk->vendor_name) {
-                       strncpy(card->longname, quirk->vendor_name, sizeof(card->longname) - 2);
-                       card->longname[sizeof(card->longname) - 2] = '\0';
-                       len = strlen(card->longname);
+                       len = strlcpy(card->longname, quirk->vendor_name, sizeof(card->longname));
                } else {
                        len = 0;
                }
        }
-       if (len > 0) {
-               card->longname[len] = ' ';
-               len++;
-       }
-       card->longname[len] = '\0';
+       if (len > 0)
+               strlcat(card->longname, ' ', sizeof(card->longname));
+
+       len = strlen(card->longname);
+
        if ((!dev->descriptor.iProduct
             || usb_string(dev, dev->descriptor.iProduct,
                           card->longname + len, sizeof(card->longname) - len) <= 0)
            && quirk && quirk->product_name) {
-               strncpy(card->longname + len, quirk->product_name, sizeof(card->longname) - len - 1);
-               card->longname[sizeof(card->longname) - 1] = '\0';
+               strlcat(card->longname, quirk->product_name, sizeof(card->longname));
        }
-       /* add device path to longname */
-       len = strlen(card->longname);
-       if (sizeof(card->longname) - len > 10) {
-               strcpy(card->longname + len, " at ");
-               len += 4;
+
+       len = strlcat(card->longname, " at ", sizeof(card->longname));
+
+       if (len < sizeof(card->longname))
                usb_make_path(dev, card->longname + len, sizeof(card->longname) - len);
-       }
 
        *rchip = chip;
        return 0;
index c9a5b382bda538a2a3d444ed9a0c84896159adf3..b5b04447f499e103b4191de4e80afd717795454a 100644 (file)
@@ -164,9 +164,7 @@ static int check_mapped_name(mixer_build_t *state, int unitid, int control, char
                if (p->id == unitid &&
                    (! control || ! p->control || control == p->control)) {
                        buflen--;
-                       strncpy(buf, p->name, buflen);
-                       buf[buflen] = 0;
-                       return strlen(buf);
+                       return strlcpy(buf, p->name, buflen);
                }
        }
        return 0;
@@ -816,7 +814,8 @@ static void build_feature_ctl(mixer_build_t *state, unsigned char *desc,
                        if (! len)
                                len = get_term_name(state, &state->oterm, kctl->id.name, sizeof(kctl->id.name), 1);
                        if (! len)
-                               len = sprintf(kctl->id.name, "Feature %d", unitid);
+                               len = snprintf(kctl->id.name, sizeof(kctl->id.name),
+                                              "Feature %d", unitid);
                }
                /* determine the stream direction:
                 * if the connected output is USB stream, then it's likely a
@@ -824,24 +823,19 @@ static void build_feature_ctl(mixer_build_t *state, unsigned char *desc,
                 */
                if (! mapped_name && ! (state->oterm.type >> 16)) {
                        if ((state->oterm.type & 0xff00) == 0x0100) {
-                               if (len + 8 < sizeof(kctl->id.name)) {
-                                       strcpy(kctl->id.name + len, " Capture");
-                                       len += 8;
-                               }
+                               len = strlcat(kctl->id.name, " Capture", sizeof(kctl->id.name));
                        } else {
-                               if (len + 9 < sizeof(kctl->id.name)) {
-                                       strcpy(kctl->id.name + len, " Playback");
-                                       len += 9;
-                               }
+                               len = strlcat(kctl->id.name + len, " Playback", sizeof(kctl->id.name));
                        }
                }
-               if (len + 7 < sizeof(kctl->id.name))
-                       strcpy(kctl->id.name + len, control == USB_FEATURE_MUTE ? " Switch" : " Volume");
+               strlcat(kctl->id.name + len, control == USB_FEATURE_MUTE ? " Switch" : " Volume",
+                       sizeof(kctl->id.name));
                break;
 
        default:
                if (! len)
-                       strcpy(kctl->id.name, audio_feature_info[control-1].name);
+                       strlcpy(kctl->id.name, audio_feature_info[control-1].name,
+                               sizeof(kctl->id.name));
                break;
        }
 
@@ -969,8 +963,7 @@ static void build_mixer_unit_ctl(mixer_build_t *state, unsigned char *desc,
                len = get_term_name(state, &iterm, kctl->id.name, sizeof(kctl->id.name), 0);
        if (! len)
                len = sprintf(kctl->id.name, "Mixer Source %d", in_ch);
-       if (len + 7 < sizeof(kctl->id.name))
-               strcpy(kctl->id.name + len, " Volume");
+       strlcat(kctl->id.name + len, " Volume", sizeof(kctl->id.name));
 
        snd_printdd(KERN_INFO "[%d] MU [%s] ch = %d, val = %d/%d\n",
                    cval->id, kctl->id.name, cval->channels, cval->min, cval->max);
@@ -1189,22 +1182,18 @@ static int build_audio_procunit(mixer_build_t *state, int unitid, unsigned char
                if (check_mapped_name(state, unitid, cval->control, kctl->id.name, sizeof(kctl->id.name)))
                        ;
                else if (info->name)
-                       strcpy(kctl->id.name, info->name);
+                       strlcpy(kctl->id.name, info->name, sizeof(kctl->id.name));
                else {
                        nameid = dsc[12 + num_ins + dsc[11 + num_ins]];
                        len = 0;
                        if (nameid)
                                len = snd_usb_copy_string_desc(state, nameid, kctl->id.name, sizeof(kctl->id.name));
-                       if (! len) {
-                               strncpy(kctl->id.name, name, sizeof(kctl->id.name) - 1);
-                               kctl->id.name[sizeof(kctl->id.name)-1] = 0;
-                       }
-               }
-               len = strlen(kctl->id.name);
-               if (len + sizeof(valinfo->suffix) + 1 < sizeof(kctl->id.name)) {
-                       kctl->id.name[len] = ' ';
-                       strcpy(kctl->id.name + len + 1, valinfo->suffix);
+                       if (! len)
+                               strlcpy(kctl->id.name, name, sizeof(kctl->id.name));
                }
+               strlcat(kctl->id.name, ' ', sizeof(kctl->id.name));
+               strlcat(kctl->id.name, valinfo->suffix, sizeof(kctl->id.name));
+
                snd_printdd(KERN_INFO "[%d] PU [%s] ch = %d, val = %d/%d\n",
                            cval->id, kctl->id.name, cval->channels, cval->min, cval->max);
                if ((err = add_control_to_empty(state->chip->card, kctl)) < 0)
@@ -1402,14 +1391,12 @@ static int parse_audio_selector_unit(mixer_build_t *state, int unitid, unsigned
                len = get_term_name(state, &state->oterm,
                                    kctl->id.name, sizeof(kctl->id.name), 0);
                if (! len)
-                       len = sprintf(kctl->id.name, "USB");
-               if ((state->oterm.type & 0xff00) == 0x0100) {
-                       if (len + 15 < sizeof(kctl->id.name))
-                               strcpy(kctl->id.name + len, " Capture Source");
-               } else {
-                       if (len + 16 < sizeof(kctl->id.name))
-                               strcpy(kctl->id.name + len, " Playback Source");
-               }
+                       strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name));
+
+               if ((state->oterm.type & 0xff00) == 0x0100)
+                       strlcat(kctl->id.name, " Capture Source", sizeof(kctl->id.name));
+               else
+                       strlcat(kctl->id.name, " Playback Source", sizeof(kctl->id.name));
        }
 
        snd_printdd(KERN_INFO "[%d] SU [%s] items = %d\n",