提交 67c1e114 编写于 作者: L leon

fix coding style

上级 3494a968
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
#define LOADCFG_BUF_SIZE 128 // loadcfg, max buffer for one cmdline #define LOADCFG_BUF_SIZE 128 // loadcfg, max buffer for one cmdline
#define LOADCFG_MAX_FILE_LEN 51200 // loadcfg, max file size is 50K #define LOADCFG_MAX_FILE_LEN 51200 // loadcfg, max file size is 50K
#define LOADCFG_MAX_LOOP 20 // loadcfg, to prevent to be trapped in infite loop #define LOADCFG_MAX_LOOP 20 // loadcfg, to prevent to be trapped in infite loop
#define OCTAL_TYPE 8 //8 means octal to decimal #define OCTAL_TYPE 8 // 8 means octal to decimal
static const char *g_supportCfg[] = { static const char *g_supportCfg[] = {
"/patch/fstab.cfg", "/patch/fstab.cfg",
}; };
...@@ -321,7 +321,7 @@ static void DoMount(const char* cmdContent) ...@@ -321,7 +321,7 @@ static void DoMount(const char* cmdContent)
} }
#ifndef OHOS_LITE #ifndef OHOS_LITE
#define OPTIONS_SIZE (128u) #define OPTIONS_SIZE 128u
static void DoInsmodInternal(const char *fileName, char *secondPtr, char *restPtr, int flags) static void DoInsmodInternal(const char *fileName, char *secondPtr, char *restPtr, int flags)
{ {
int fd = -1; int fd = -1;
...@@ -332,7 +332,7 @@ static void DoInsmodInternal(const char *fileName, char *secondPtr, char *restPt ...@@ -332,7 +332,7 @@ static void DoInsmodInternal(const char *fileName, char *secondPtr, char *restPt
if (snprintf_s(options, sizeof(options), OPTIONS_SIZE -1, "%s %s", secondPtr, restPtr) == -1) { if (snprintf_s(options, sizeof(options), OPTIONS_SIZE -1, "%s %s", secondPtr, restPtr) == -1) {
goto out; goto out;
} }
} else { } else if (secondPtr != NULL) {
if (strncpy_s(options, OPTIONS_SIZE - 1, secondPtr, strlen(secondPtr)) != 0) { if (strncpy_s(options, OPTIONS_SIZE - 1, secondPtr, strlen(secondPtr)) != 0) {
goto out; goto out;
} }
......
...@@ -70,18 +70,6 @@ ...@@ -70,18 +70,6 @@
int g_ueventFD = -1; int g_ueventFD = -1;
#define CHECK_RESULT_DONE(ret, do, another) \
if (ret) { \
do; \
} else { \
another; \
}
#define CHECK_RETURN(ret, statement) \
if (!(ret)) { \
statement; \
}
struct Uevent { struct Uevent {
const char *action; const char *action;
const char *path; const char *path;
...@@ -106,7 +94,7 @@ static struct ListNode g_platformNames = { ...@@ -106,7 +94,7 @@ static struct ListNode g_platformNames = {
.prev = &g_platformNames, .prev = &g_platformNames,
}; };
const char *TRIGGER = "/dev/.trigger_uevent"; const char *g_trigger = "/dev/.trigger_uevent";
static void HandleUevent(); static void HandleUevent();
static int UeventFD() static int UeventFD()
...@@ -156,14 +144,14 @@ void Trigger(const char *sysPath) ...@@ -156,14 +144,14 @@ void Trigger(const char *sysPath)
static void RetriggerUevent() static void RetriggerUevent()
{ {
if (access(TRIGGER, F_OK) == 0) { if (access(g_trigger, F_OK) == 0) {
printf("Skip trigger uevent, alread done\n"); printf("Skip trigger uevent, alread done\n");
return; return;
} }
Trigger("/sys/class"); Trigger("/sys/class");
Trigger("/sys/block"); Trigger("/sys/block");
Trigger("/sys/devices"); Trigger("/sys/devices");
int fd = open(TRIGGER, O_WRONLY | O_CREAT | O_CLOEXEC, DEFAULT_MODE); int fd = open(g_trigger, O_WRONLY | O_CREAT | O_CLOEXEC, DEFAULT_MODE);
if (fd > 0) { if (fd > 0) {
close(fd); close(fd);
} }
...@@ -347,15 +335,15 @@ static char **ParsePlatformBlockDevice(const struct Uevent *uevent) ...@@ -347,15 +335,15 @@ static char **ParsePlatformBlockDevice(const struct Uevent *uevent)
char *p = NULL; char *p = NULL;
struct PlatformNode *pDev = FindPlatformDevice(uevent->path); struct PlatformNode *pDev = FindPlatformDevice(uevent->path);
CHECK_RESULT_DONE(pDev, device = pDev->name; type = "platform", printf("Non platform device.\n"); return NULL); if (!pDev) {
char **links = malloc(sizeof(char *) * LINK_NUMBER);
if (!links) {
return NULL; return NULL;
} }
if (memset_s(links, sizeof(char *) * LINK_NUMBER, 0, sizeof(char *) * LINK_NUMBER) != 0) { device = pDev->name;
type = "platform";
char **links = calloc(sizeof(char *), LINK_NUMBER);
if (!links) {
return NULL; return NULL;
} }
printf("found %s device %s\n", type, device);
if (snprintf_s(linkPath, sizeof(linkPath), sizeof(linkPath), "/dev/block/%s/%s", type, device) == -1) { if (snprintf_s(linkPath, sizeof(linkPath), sizeof(linkPath), "/dev/block/%s/%s", type, device) == -1) {
return NULL; return NULL;
} }
...@@ -601,6 +589,16 @@ static const char *ParseDeviceName(const struct Uevent *uevent, unsigned int len ...@@ -601,6 +589,16 @@ static const char *ParseDeviceName(const struct Uevent *uevent, unsigned int len
return name; return name;
} }
static void FindCharEnd(const char *parent)
{
while (*++parent) {
if (*parent == '/') {
return;
}
}
return;
}
static char **GetCharacterDeviceSymlinks(const struct Uevent *uevent) static char **GetCharacterDeviceSymlinks(const struct Uevent *uevent)
{ {
char *slash = NULL; char *slash = NULL;
...@@ -608,11 +606,11 @@ static char **GetCharacterDeviceSymlinks(const struct Uevent *uevent) ...@@ -608,11 +606,11 @@ static char **GetCharacterDeviceSymlinks(const struct Uevent *uevent)
int width; int width;
struct PlatformNode *pDev = FindPlatformDevice(uevent->path); struct PlatformNode *pDev = FindPlatformDevice(uevent->path);
CHECK_RETURN(pDev, return NULL); if (!pDev) {
return NULL;
char **links = malloc(sizeof(char *) * SYS_LINK_NUMBER); }
CHECK_RETURN(links, return NULL); char **links = calloc(sizeof(char *), SYS_LINK_NUMBER);
if (memset_s(links, sizeof(char *) * SYS_LINK_NUMBER, 0, sizeof(char *) * SYS_LINK_NUMBER) != 0) { if (!links) {
return NULL; return NULL;
} }
...@@ -624,17 +622,9 @@ static char **GetCharacterDeviceSymlinks(const struct Uevent *uevent) ...@@ -624,17 +622,9 @@ static char **GetCharacterDeviceSymlinks(const struct Uevent *uevent)
if (!strncmp(parent, "/usb", DEV_USB)) { if (!strncmp(parent, "/usb", DEV_USB)) {
/* skip root hub name and device. use device interface */ /* skip root hub name and device. use device interface */
while (*++parent) { FindCharEnd(parent);
if (*parent == '/') {
break;
}
}
if (*parent) { if (*parent) {
while (*++parent) { FindCharEnd(parent);
if (*parent == '/') {
break;
}
}
} }
if (!*parent) { if (!*parent) {
goto err; goto err;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册