From 05adcbd4fbdda73329d9cd6a6b91e30624705a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=98=E6=99=A8=E9=98=B3?= <690928667@qq.com> Date: Thu, 18 Jul 2024 01:06:50 +0000 Subject: [PATCH 1/2] =?UTF-8?q?update=20adapter/khdf/linux/platform/uart/u?= =?UTF-8?q?art=5Fadapter.c.=20Signed-off-by:=20=E4=BB=98=E6=99=A8=E9=98=B3?= =?UTF-8?q?=20<690928667@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 付晨阳 <690928667@qq.com> --- .../khdf/linux/platform/uart/uart_adapter.c | 63 +++++++++++++------ 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/adapter/khdf/linux/platform/uart/uart_adapter.c b/adapter/khdf/linux/platform/uart/uart_adapter.c index 89af4e0aa..1dffb17fa 100644 --- a/adapter/khdf/linux/platform/uart/uart_adapter.c +++ b/adapter/khdf/linux/platform/uart/uart_adapter.c @@ -20,7 +20,6 @@ #include #include #include -#include #include "device_resource_if.h" #include "hdf_base.h" #include "hdf_log.h" @@ -35,12 +34,16 @@ #define UART_NAME_LEN 20 #define UART_PATHNAME_LEN (UART_NAME_LEN + 20) -static char g_driverName[UART_NAME_LEN]; +struct UartPriv { + void *fileFp; + char driverName[UART_NAME_LEN]; +} ; static int32_t UartAdapterInit(struct UartHost *host) { char name[UART_PATHNAME_LEN] = {0}; struct file *fp = NULL; + struct UartPriv *uartpriv = NULL; #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) mm_segment_t oldfs; #endif @@ -49,7 +52,8 @@ static int32_t UartAdapterInit(struct UartHost *host) HDF_LOGE("UartAdapterInit: host is null!"); return HDF_ERR_INVALID_OBJECT; } - if (sprintf_s(name, UART_PATHNAME_LEN - 1, "/dev/%s%d", g_driverName, host->num) < 0) { + uartpriv = (struct UartPriv *)host->priv; + if (sprintf_s(name, UART_PATHNAME_LEN - 1, "/dev/%s%d", uartpriv->driverName, host->num) < 0) { return HDF_FAILURE; } #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) @@ -60,30 +64,31 @@ static int32_t UartAdapterInit(struct UartHost *host) if (IS_ERR(fp)) { HDF_LOGE("UartAdapterInit: filp_open %s fail!", name); #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) - set_fs(oldfs); + set_fs(oldfs); #endif return HDF_FAILURE; } #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) - set_fs(oldfs); + set_fs(oldfs); #endif - host->priv = fp; + uartpriv->fileFp = fp; return HDF_SUCCESS; } static int32_t UartAdapterDeInit(struct UartHost *host) { struct file *fp = NULL; + struct UartPriv *uartpriv = NULL; #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) mm_segment_t oldfs; -#endif +#endi if (host == NULL) { HDF_LOGE("UartAdapterDeInit: host is null!"); return HDF_ERR_INVALID_OBJECT; } - - fp = (struct file *)host->priv; + uartpriv = (struct UartPriv *)host->priv; + fp = (struct file *)uartpriv->fileFp; #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) oldfs = get_fs(); set_fs(KERNEL_DS); @@ -94,7 +99,7 @@ static int32_t UartAdapterDeInit(struct UartHost *host) #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) set_fs(oldfs); #endif - host->priv = NULL; + uartpriv->fileFp = NULL; return HDF_SUCCESS; } @@ -103,6 +108,7 @@ static int32_t UartAdapterRead(struct UartHost *host, uint8_t *data, uint32_t si loff_t pos = 0; int ret; struct file *fp = NULL; + struct UartPriv *uartpriv = NULL; char *p = (char *)data; #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) mm_segment_t oldfs; @@ -114,7 +120,8 @@ static int32_t UartAdapterRead(struct UartHost *host, uint8_t *data, uint32_t si return HDF_ERR_INVALID_OBJECT; } - fp = (struct file *)host->priv; + uartpriv = (struct UartPriv *)host->priv; + fp = (struct file *)uartpriv->fileFp; #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) oldfs = get_fs(); set_fs(KERNEL_DS); @@ -138,6 +145,7 @@ static int32_t UartAdapterWrite(struct UartHost *host, uint8_t *data, uint32_t s loff_t pos = 0; int ret; struct file *fp = NULL; + struct UartPriv *uartpriv = NULL; char *p = (char *)data; #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) mm_segment_t oldfs; @@ -148,7 +156,8 @@ static int32_t UartAdapterWrite(struct UartHost *host, uint8_t *data, uint32_t s return HDF_ERR_INVALID_OBJECT; } - fp = (struct file *)host->priv; + uartpriv = (struct UartPriv *)host->priv; + fp = (struct file *)uartpriv->fileFp; #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) oldfs = get_fs(); set_fs(KERNEL_DS); @@ -246,12 +255,14 @@ static int32_t UartAdapterGetBaud(struct UartHost *host, uint32_t *baudRate) { struct termios termios; struct file *fp = NULL; + struct UartPriv *uartpriv = NULL; if (host == NULL) { HDF_LOGE("UartAdapterGetBaud: host is null!"); return HDF_ERR_INVALID_OBJECT; } - fp = (struct file *)host->priv; + uartpriv = (struct UartPriv *)host->priv; + fp = (struct file *)uartpriv->fileFp; if (baudRate == NULL) { HDF_LOGE("UartAdapterGetBaud: baudRate is null!"); return HDF_ERR_INVALID_PARAM; @@ -319,13 +330,15 @@ static int32_t UartAdapterSetBaud(struct UartHost *host, uint32_t baudRate) struct termios termios; struct serial_struct serial; struct file *fp = NULL; + struct UartPriv *uartpriv = NULL; int ret; if (host == NULL) { HDF_LOGE("UartAdapterSetBaud: host is null!"); return HDF_ERR_INVALID_OBJECT; } - fp = (struct file *)host->priv; + uartpriv = (struct UartPriv *)host->priv; + fp = (struct file *)uartpriv->fileFp; if (UartAdapterIoctlInner(fp, TCGETS, (unsigned long)&termios) < 0) { HDF_LOGE("UartAdapterSetBaud: tcgets fail!"); @@ -417,13 +430,15 @@ static int32_t UartAdapterGetAttribute(struct UartHost *host, struct UartAttribu { struct termios termios; struct file *fp = NULL; + struct UartPriv *uartpriv = NULL; int ret; if (host == NULL) { HDF_LOGE("UartAdapterGetAttribute: host is null!"); return HDF_ERR_INVALID_OBJECT; } - fp = (struct file *)host->priv; + uartpriv = (struct UartPriv *)host->priv; + fp = (struct file *)uartpriv->fileFp; if (attribute == NULL) { HDF_LOGE("UartAdapterGetAttribute: attribute is null!"); return HDF_ERR_INVALID_PARAM; @@ -445,13 +460,15 @@ static int32_t UartAdapterSetAttribute(struct UartHost *host, struct UartAttribu { struct termios termios; struct file *fp = NULL; + struct UartPriv *uartpriv = NULL; int ret; if (host == NULL) { HDF_LOGE("UartAdapterSetAttribute: host is null!"); return HDF_ERR_INVALID_OBJECT; } - fp = (struct file *)host->priv; + uartpriv = (struct UartPriv *)host->priv; + fp = (struct file *)uartpriv->fileFp; if (attribute == NULL) { HDF_LOGE("UartAdapterSetAttribute: attribute is null!"); return HDF_ERR_INVALID_PARAM; @@ -520,6 +537,7 @@ static int32_t HdfUartInit(struct HdfDeviceObject *obj) int32_t ret; struct DeviceResourceIface *iface = NULL; struct UartHost *host = NULL; + struct UartPriv *uartpriv = NULL; const char *drName = NULL; HDF_LOGI("HdfUartInit: entry!"); @@ -546,17 +564,21 @@ static int32_t HdfUartInit(struct HdfDeviceObject *obj) HDF_LOGE("HdfUartInit: read driver_name fail!"); return HDF_FAILURE; } - g_driverName[UART_NAME_LEN - 1] = 0; if (strlen(drName) > (UART_NAME_LEN - 1)) { HDF_LOGE("HdfUartInit: illegal length of drName!"); return HDF_FAILURE; } - ret = memcpy_s(g_driverName, UART_NAME_LEN, drName, strlen(drName)); - if (ret != EOK) { - HDF_LOGE("HdfUartInit: memcpy_s fail!"); + uartpriv = OsalMemCalloc(sizeof(struct UartPriv)); + if (uartpriv == NULL) { + HDF_LOGE("HdfUartInit: malloc UartPriv fail!"); + return HDF_FAILURE; + } + if (memcpy_s(uartpriv->driverName, UART_NAME_LEN, drName, strlen(drName)) < 0) { + HDF_LOGE("HdfUartInit: memcpy_s drName fail!"); return HDF_FAILURE; } host->method = &g_uartHostMethod; + OsalMemFree(host->priv); return HDF_SUCCESS; } @@ -570,6 +592,7 @@ static void HdfUartRelease(struct HdfDeviceObject *obj) return; } host = UartHostFromDevice(obj); + host->priv = uartpriv; UartHostDestroy(host); } -- Gitee From 05757e75cf8a6d873d909bde9885a8fe66556aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=98=E6=99=A8=E9=98=B3?= <690928667@qq.com> Date: Thu, 18 Jul 2024 01:52:14 +0000 Subject: [PATCH 2/2] =?UTF-8?q?update=20adapter/khdf/linux/platform/uart/u?= =?UTF-8?q?art=5Fadapter.c.=20Signed-off-by:=20=E4=BB=98=E6=99=A8=E9=98=B3?= =?UTF-8?q?=20<690928667@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 付晨阳 <690928667@qq.com> --- adapter/khdf/linux/platform/uart/uart_adapter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapter/khdf/linux/platform/uart/uart_adapter.c b/adapter/khdf/linux/platform/uart/uart_adapter.c index 1dffb17fa..0910d4e70 100644 --- a/adapter/khdf/linux/platform/uart/uart_adapter.c +++ b/adapter/khdf/linux/platform/uart/uart_adapter.c @@ -81,7 +81,7 @@ static int32_t UartAdapterDeInit(struct UartHost *host) struct UartPriv *uartpriv = NULL; #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) mm_segment_t oldfs; -#endi +#endif if (host == NULL) { HDF_LOGE("UartAdapterDeInit: host is null!"); -- Gitee