From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 6DEA67D30 for ; Tue, 2 Jan 2018 10:40:22 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jan 2018 01:40:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,496,1508828400"; d="scan'208";a="6690762" Received: from jguo15x-mobl3.ccr.corp.intel.com (HELO [10.67.68.69]) ([10.67.68.69]) by fmsmga002.fm.intel.com with ESMTP; 02 Jan 2018 01:40:18 -0800 To: Stephen Hemminger References: <1505880732-16539-3-git-send-email-jia.guo@intel.com> <1509567405-27439-1-git-send-email-jia.guo@intel.com> <1509567405-27439-2-git-send-email-jia.guo@intel.com> <20171225100632.055c3fc8@xeon-e3> Cc: bruce.richardson@intel.com, ferruh.yigit@intel.com, gaetan.rivet@6wind.com, thomas@monjalon.net, konstantin.ananyev@intel.com, jblunck@infradead.org, shreyansh.jain@nxp.com, jingjing.wu@intel.com, dev@dpdk.org, helin.zhang@intel.com From: "Guo, Jia" Message-ID: <61321414-3c6b-3ef8-5265-d6af5057e561@intel.com> Date: Tue, 2 Jan 2018 17:40:18 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20171225100632.055c3fc8@xeon-e3> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v6 1/2] eal: add uevent monitor for hot plug X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Jan 2018 09:40:23 -0000 On 12/26/2017 2:06 AM, Stephen Hemminger wrote: > On Thu, 2 Nov 2017 04:16:44 +0800 > Jeff Guo wrote: > >> +int >> +rte_dev_bind_driver(const char *dev_name, const char *drv_type) { > Bracket left after declaration. thanks. > > >> + snprintf(drv_override_path, sizeof(drv_override_path), >> + "/sys/bus/pci/devices/%s/driver_override", dev_name); >> + >> + /* specify the driver for a device by writing to driver_override */ >> + drv_override_fd = open(drv_override_path, O_WRONLY); >> + if (drv_override_fd < 0) { >> + RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", >> + drv_override_path, strerror(errno)); >> + goto err; >> + } > > You should not have dev functions that assume PCI. Please split into common > and bus specific code. > > make sense, will modify it into bus specific code. >> +static int >> +dev_uev_parse(const char *buf, struct rte_eal_uevent *event) >> +{ >> + char action[RTE_EAL_UEVENT_MSG_LEN]; >> + char subsystem[RTE_EAL_UEVENT_MSG_LEN]; >> + char dev_path[RTE_EAL_UEVENT_MSG_LEN]; >> + char pci_slot_name[RTE_EAL_UEVENT_MSG_LEN]; >> + int i = 0; >> + >> + memset(action, 0, RTE_EAL_UEVENT_MSG_LEN); >> + memset(subsystem, 0, RTE_EAL_UEVENT_MSG_LEN); >> + memset(dev_path, 0, RTE_EAL_UEVENT_MSG_LEN); >> + memset(pci_slot_name, 0, RTE_EAL_UEVENT_MSG_LEN); >> + >> + while (i < RTE_EAL_UEVENT_MSG_LEN) { >> + for (; i < RTE_EAL_UEVENT_MSG_LEN; i++) { >> + if (*buf) >> + break; >> + buf++; >> + } >> + if (!strncmp(buf, "libudev", 7)) { >> + buf += 7; >> + i += 7; >> + event->group = UEV_MONITOR_UDEV; >> + } >> + if (!strncmp(buf, "ACTION=", 7)) { >> + buf += 7; >> + i += 7; >> + snprintf(action, sizeof(action), "%s", buf); > Why snprintf rather than strncpy? > snprintf would no need manual write '\0' and the src length is not explicit, and if concern about the efficiency of the snprintf scan, i will constrain the value of dest buf length. >> + } else if (!strncmp(buf, "DEVPATH=", 8)) { >> + buf += 8; >> + i += 8; >> + snprintf(dev_path, sizeof(dev_path), "%s", buf); >> + } else if (!strncmp(buf, "SUBSYSTEM=", 10)) { >> + buf += 10; >> + i += 10; >> + snprintf(subsystem, sizeof(subsystem), "%s", buf); >> + } else if (!strncmp(buf, "PCI_SLOT_NAME=", 14)) { >> + buf += 14; >> + i += 14; >> + snprintf(pci_slot_name, sizeof(subsystem), "%s", buf); >> + } >> + for (; i < RTE_EAL_UEVENT_MSG_LEN; i++) { >> + if (*buf == '\0') >> + break; >> + buf++; >> + } >> + } >> + >> + if (!strncmp(subsystem, "pci", 3)) >> + event->subsystem = UEV_SUBSYSTEM_PCI; >> + if (!strncmp(action, "add", 3)) >> + event->type = RTE_EAL_DEV_EVENT_ADD; >> + if (!strncmp(action, "remove", 6)) >> + event->type = RTE_EAL_DEV_EVENT_REMOVE; >> + event->devname = pci_slot_name; > Why do you need to first capture the strings, then set state variables? > Instead why not update event->xxx directly? i think that would be more benefit to read and manage out of the loop.