Commit 971bd06d authored by Jan Kiszka's avatar Jan Kiszka

Merge remote-tracking branch 'rpm/for-upstream/next' into next

parents 04df9389 3258438a
......@@ -248,7 +248,7 @@ int main(int argc, char *argv[])
return -1;
}
strncpy(ifr.ifr_name, rxdev, IFNAMSIZ);
namecpy(ifr.ifr_name, rxdev);
printf("RX rxsock=%d, ifr_name=%s\n", rxsock, ifr.ifr_name);
if (ioctl(rxsock, SIOCGIFINDEX, &ifr) < 0) {
......@@ -282,7 +282,7 @@ int main(int argc, char *argv[])
goto failure1;
}
strncpy(ifr.ifr_name, txdev, IFNAMSIZ);
namecpy(ifr.ifr_name, txdev);
printf("TX txsock=%d, ifr_name=%s\n", txsock, ifr.ifr_name);
if (ioctl(txsock, SIOCGIFINDEX, &ifr) < 0) {
......
......@@ -40,6 +40,7 @@
#include <net/if.h>
#include <arpa/inet.h>
#include <netinet/ether.h>
#include <boilerplate/ancillaries.h>
char buffer[10*1024];
int sock;
......@@ -72,7 +73,7 @@ int main(int argc, char *argv[])
if (argc > 1) {
struct ifreq ifr;
strncpy(ifr.ifr_name, argv[1], IFNAMSIZ);
namecpy(ifr.ifr_name, argv[1]);
if (ioctl(sock, SIOCGIFINDEX, &ifr) < 0) {
perror("cannot get interface index");
close(sock);
......
......@@ -1353,7 +1353,7 @@ static void process_options (int argc, char *argv[], int max_cpus)
case 'F':
case OPT_FIFO:
use_fifo = 1;
strncpy(fifopath, optarg, strlen(optarg));
strncpy(fifopath, optarg, sizeof(fifopath) - 1);
break;
case 'H':
......@@ -1458,7 +1458,7 @@ static void process_options (int argc, char *argv[], int max_cpus)
case 'T':
case OPT_TRACER:
tracetype = CUSTOM;
strncpy(tracer, optarg, sizeof(tracer));
strncpy(tracer, optarg, sizeof(tracer) - 1);
break;
case 'u':
case OPT_UNBUFFERED:
......
......@@ -34,7 +34,7 @@ void __namecpy_requires_character_array_as_destination(void);
({ \
if (!__builtin_types_compatible_p(typeof(__dst), char[])) \
__namecpy_requires_character_array_as_destination(); \
strncpy((__dst), __src, sizeof(__dst) - 1); \
strncpy((__dst), __src, sizeof(__dst)); \
__dst[sizeof(__dst) - 1] = '\0'; \
__dst; \
})
......
......@@ -46,14 +46,6 @@
#define __weak __attribute__((__weak__))
#endif
#ifndef __const
#define __const __attribute__((__const__))
#endif
#ifndef __pure
#define __pure __attribute__((__pure__))
#endif
#ifndef __maybe_unused
#define __maybe_unused __attribute__((__unused__))
#endif
......
......@@ -58,7 +58,7 @@ void __knamecpy_requires_character_array_as_destination(void);
({ \
if (!__builtin_types_compatible_p(typeof(__dst), char[])) \
__knamecpy_requires_character_array_as_destination(); \
strncpy((__dst), __src, sizeof(__dst) - 1); \
strncpy((__dst), __src, sizeof(__dst)); \
__dst[sizeof(__dst) - 1] = '\0'; \
__dst; \
})
......
......@@ -2432,6 +2432,7 @@ static void igb_remove(struct pci_dev *pdev)
struct igb_adapter *adapter = rtnetdev_priv(netdev);
struct e1000_hw *hw = &adapter->hw;
rtdev_down(netdev);
igb_down(adapter);
pm_runtime_get_noresume(&pdev->dev);
......@@ -5066,6 +5067,9 @@ static int igb_mii_ioctl(struct rtnet_device *netdev, struct ifreq *ifr, int cmd
**/
static int igb_ioctl(struct rtnet_device *netdev, struct ifreq *ifr, int cmd)
{
if (rtdm_in_rt_context())
return -ENOSYS;
switch (cmd) {
case SIOCGMIIPHY:
case SIOCGMIIREG:
......
......@@ -231,6 +231,10 @@ unsigned int rt_hard_mtu(struct rtnet_device *rtdev, unsigned int priority);
int rtdev_open(struct rtnet_device *rtdev);
int rtdev_close(struct rtnet_device *rtdev);
int rtdev_up(struct rtnet_device *rtdev,
struct rtnet_core_cmd *cmd);
int rtdev_down(struct rtnet_device *rtdev);
int rtdev_map_rtskb(struct rtskb *skb);
void rtdev_unmap_rtskb(struct rtskb *skb);
......
......@@ -650,7 +650,110 @@ void rtdev_del_event_hook(struct rtdev_event_hook *hook)
mutex_unlock(&rtnet_devices_nrt_lock);
}
int rtdev_up(struct rtnet_device *rtdev, struct rtnet_core_cmd *cmd)
{
struct list_head *entry;
struct rtdev_event_hook *hook;
int ret = 0;
if (mutex_lock_interruptible(&rtdev->nrt_lock))
return -ERESTARTSYS;
/* We cannot change the promisc flag or the hardware address if
the device is already up. */
if ((rtdev->flags & IFF_UP) &&
(((cmd->args.up.set_dev_flags | cmd->args.up.clear_dev_flags) &
IFF_PROMISC) ||
(cmd->args.up.dev_addr_type != ARPHRD_VOID))) {
ret = -EBUSY;
goto out;
}
if (cmd->args.up.dev_addr_type != ARPHRD_VOID &&
cmd->args.up.dev_addr_type != rtdev->type) {
ret = -EINVAL;
goto out;
}
/* Skip upon extraneous call only after args have been checked. */
if (test_and_set_bit(PRIV_FLAG_UP, &rtdev->priv_flags))
goto out;
rtdev->flags |= cmd->args.up.set_dev_flags;
rtdev->flags &= ~cmd->args.up.clear_dev_flags;
if (cmd->args.up.dev_addr_type != ARPHRD_VOID)
memcpy(rtdev->dev_addr, cmd->args.up.dev_addr, MAX_ADDR_LEN);
ret = rtdev_open(rtdev); /* also == 0 if rtdev is already up */
if (ret == 0) {
mutex_lock(&rtnet_devices_nrt_lock);
list_for_each(entry, &event_hook_list) {
hook = list_entry(entry, struct rtdev_event_hook, entry);
if (hook->ifup)
hook->ifup(rtdev, cmd);
}
mutex_unlock(&rtnet_devices_nrt_lock);
} else
clear_bit(PRIV_FLAG_UP, &rtdev->priv_flags);
out:
mutex_unlock(&rtdev->nrt_lock);
return ret;
}
EXPORT_SYMBOL_GPL(rtdev_up);
int rtdev_down(struct rtnet_device *rtdev)
{
struct list_head *entry;
struct rtdev_event_hook *hook;
rtdm_lockctx_t context;
int ret = 0;
if (mutex_lock_interruptible(&rtdev->nrt_lock))
return -ERESTARTSYS;
/* spin lock required for sync with routing code */
rtdm_lock_get_irqsave(&rtdev->rtdev_lock, context);
if (test_bit(PRIV_FLAG_ADDING_ROUTE, &rtdev->priv_flags)) {
ret = -EBUSY;
goto fail;
}
if (!test_and_clear_bit(PRIV_FLAG_UP, &rtdev->priv_flags))
goto fail;
rtdm_lock_put_irqrestore(&rtdev->rtdev_lock, context);
if (rtdev->mac_detach != NULL)
ret = rtdev->mac_detach(rtdev);
if (ret == 0) {
mutex_lock(&rtnet_devices_nrt_lock);
list_for_each(entry, &event_hook_list) {
hook = list_entry(entry, struct rtdev_event_hook, entry);
if (hook->ifdown)
hook->ifdown(rtdev);
}
mutex_unlock(&rtnet_devices_nrt_lock);
ret = rtdev_close(rtdev);
}
out:
mutex_unlock(&rtdev->nrt_lock);
return ret;
fail:
rtdm_lock_put_irqrestore(&rtdev->rtdev_lock, context);
goto out;
}
EXPORT_SYMBOL_GPL(rtdev_down);
/***
* rtdev_open
......
......@@ -88,16 +88,11 @@ static long rtnet_ioctl(struct file *file,
return -ENOTTY;
}
static int rtnet_core_ioctl(struct rtnet_device *rtdev, unsigned int request,
unsigned long arg)
{
struct rtnet_core_cmd cmd;
struct list_head *entry;
struct rtdev_event_hook *hook;
int ret;
rtdm_lockctx_t context;
ret = copy_from_user(&cmd, (void *)arg, sizeof(cmd));
......@@ -106,87 +101,11 @@ static int rtnet_core_ioctl(struct rtnet_device *rtdev, unsigned int request,
switch (request) {
case IOC_RT_IFUP:
if (mutex_lock_interruptible(&rtdev->nrt_lock))
return -ERESTARTSYS;
/* We cannot change the promisc flag or the hardware address if
the device is already up. */
if ((rtdev->flags & IFF_UP) &&
(((cmd.args.up.set_dev_flags | cmd.args.up.clear_dev_flags) &
IFF_PROMISC) ||
(cmd.args.up.dev_addr_type != ARPHRD_VOID))) {
ret = -EBUSY;
goto up_out;
}
rtdev->flags |= cmd.args.up.set_dev_flags;
rtdev->flags &= ~cmd.args.up.clear_dev_flags;
if (cmd.args.up.dev_addr_type != ARPHRD_VOID) {
if (cmd.args.up.dev_addr_type != rtdev->type) {
ret = -EINVAL;
goto up_out;
}
memcpy(rtdev->dev_addr, cmd.args.up.dev_addr, MAX_ADDR_LEN);
}
set_bit(PRIV_FLAG_UP, &rtdev->priv_flags);
ret = rtdev_open(rtdev); /* also == 0 if rtdev is already up */
if (ret == 0) {
mutex_lock(&rtnet_devices_nrt_lock);
list_for_each(entry, &event_hook_list) {
hook = list_entry(entry, struct rtdev_event_hook, entry);
if (hook->ifup)
hook->ifup(rtdev, &cmd);
}
mutex_unlock(&rtnet_devices_nrt_lock);
} else
clear_bit(PRIV_FLAG_UP, &rtdev->priv_flags);
up_out:
mutex_unlock(&rtdev->nrt_lock);
ret = rtdev_up(rtdev, &cmd);
break;
case IOC_RT_IFDOWN:
if (mutex_lock_interruptible(&rtdev->nrt_lock))
return -ERESTARTSYS;
/* spin lock required for sync with routing code */
rtdm_lock_get_irqsave(&rtdev->rtdev_lock, context);
if (test_bit(PRIV_FLAG_ADDING_ROUTE, &rtdev->priv_flags)) {
rtdm_lock_put_irqrestore(&rtdev->rtdev_lock, context);
mutex_unlock(&rtdev->nrt_lock);
return -EBUSY;
}
clear_bit(PRIV_FLAG_UP, &rtdev->priv_flags);
rtdm_lock_put_irqrestore(&rtdev->rtdev_lock, context);
ret = 0;
if (rtdev->mac_detach != NULL)
ret = rtdev->mac_detach(rtdev);
if (ret == 0) {
mutex_lock(&rtnet_devices_nrt_lock);
list_for_each(entry, &event_hook_list) {
hook = list_entry(entry, struct rtdev_event_hook, entry);
if (hook->ifdown)
hook->ifdown(rtdev);
}
mutex_unlock(&rtnet_devices_nrt_lock);
ret = rtdev_close(rtdev);
}
mutex_unlock(&rtdev->nrt_lock);
ret = rtdev_down(rtdev);
break;
case IOC_RT_IFINFO:
......
......@@ -31,6 +31,7 @@
#include <errno.h>
#include <getopt.h>
#include <sys/mman.h>
#include <boilerplate/ancillaries.h>
#include <rtdm/can.h>
......@@ -81,7 +82,7 @@ static int string_to_ctrlmode(char *str)
int main(int argc, char *argv[])
{
char ifname[16];
char ifname[IFNAMSIZ];
int can_fd = -1;
int new_baudrate = -1;
int new_mode = -1;
......@@ -159,8 +160,8 @@ int main(int argc, char *argv[])
return 0;
}
strncpy(ifname, argv[optind], IFNAMSIZ);
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
namecpy(ifname, argv[optind]);
namecpy(ifr.ifr_name, ifname);
if (optind == argc - 2) { /* Get mode setting */
new_mode = string_to_mode(argv[optind + 1]);
......
......@@ -7,6 +7,7 @@
#include <getopt.h>
#include <alchemy/task.h>
#include <boilerplate/ancillaries.h>
#include <rtdm/can.h>
......@@ -248,7 +249,7 @@ int main(int argc, char **argv)
if (verbose)
printf("interface %s\n", argv[optind]);
strncpy(ifr.ifr_name, argv[optind], IFNAMSIZ);
namecpy(ifr.ifr_name, argv[optind]);
if (verbose)
printf("s=%d, ifr_name=%s\n", s, ifr.ifr_name);
......
......@@ -6,6 +6,7 @@
#include <errno.h>
#include <getopt.h>
#include <boilerplate/ancillaries.h>
#include <alchemy/task.h>
#include <alchemy/timer.h>
......@@ -231,7 +232,7 @@ int main(int argc, char **argv)
printf("Using loopback=%d\n", loopback);
}
strncpy(ifr.ifr_name, argv[optind], IFNAMSIZ);
namecpy(ifr.ifr_name, argv[optind]);
if (verbose)
printf("s=%d, ifr_name=%s\n", s, ifr.ifr_name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment