Skip to content

Commit e8ad7a8

Browse files
saranyagopal1sysopenci
authored andcommitted
EM: Fix for battery technology string not showing up
Battery host utility sends an initial message with all constant fields like battery technology, manaufacturer, serial number, etc. This message is of different size from subsequent messages. Since HAL is waiting for a particular amount of bytes, this message is not processed by HAL. So, reuse the same msgbuf which is used for other messages. This will also help in saving few bytes in memory. Also, this patch fixes a warning on format-truncation. Since base_path (source) and sysfs_path (destination) have same array size, compiler complains that there may be a truncation during snprintf operation. Reduce the base_path (destination) array size to avoid this warning. Tracked-On: OAM-91507 Signed-off-by: Saranya Gopal <saranya.gopal@intel.com>
1 parent feb1fe3 commit e8ad7a8

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

bin/batsys

128 Bytes
Binary file not shown.

vm_battery_utility/battery_sysfsread.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct monitor_pkt monitortemp;
4040
int start_connection(struct sockaddr_vm sa_listen, int listen_fd, socklen_t socklen_client, int *m_acpidsock);
4141

4242
int client_fd = 0;
43-
char base_path[120] = "/sys/class/power_supply/";
43+
char base_path[100] = "/sys/class/power_supply/";
4444

4545
/*
4646
* get_battery_module_name : This function gets the battery module
@@ -87,7 +87,6 @@ void read_sysfs_values(char *filename, void *buf, int len, int flag)
8787
return;
8888
}
8989

90-
9190
if (flag==0)
9291
fread(buf, len, 1, fp);
9392
else
@@ -193,14 +192,9 @@ int send_pkt()
193192
{
194193
char msgbuf[1024] = {0};
195194
struct header head;
196-
char *initialbuf = (char *)malloc(sizeof(head) + sizeof(initpkt) + sizeof(monitorpkt));
197195
bool flag = 0;
198196
int return_value = 0;
199197

200-
if (initialbuf == NULL) {
201-
printf("Initialbuf malloc failed\n");
202-
return -1;
203-
}
204198
#if debug_local_flag
205199
char battery_module_name[50];
206200

@@ -216,24 +210,22 @@ int send_pkt()
216210
/* Read and store the battery sysfs values for the 1st time */
217211
read_store_values();
218212
fill_header(&head, 1);
219-
memcpy(initialbuf, (const unsigned char*)&head, sizeof(head));
220-
memcpy(initialbuf + sizeof(head), (const unsigned char*)&initpkt, sizeof(initpkt));
221-
memcpy(initialbuf + sizeof(head) + sizeof(initpkt), (const unsigned char*)&monitorpkt, sizeof(monitorpkt));
213+
memcpy(msgbuf, (const unsigned char*)&head, sizeof(head));
214+
memcpy(msgbuf + sizeof(head), (const unsigned char*)&initpkt, sizeof(initpkt));
215+
memcpy(msgbuf + sizeof(head) + sizeof(initpkt), (const unsigned char*)&monitorpkt, sizeof(monitorpkt));
222216
#if debug_local_flag
223217
printf("Sending initial values\n");
224218
#else
225-
return_value = send(client_fd, initialbuf, sizeof(initialbuf), MSG_DONTWAIT);
226-
if (return_value == -1) {
227-
free(initialbuf);
219+
return_value = send(client_fd, msgbuf, sizeof(msgbuf), MSG_DONTWAIT);
220+
if (return_value == -1)
228221
goto out;
229-
}
222+
memset(msgbuf, 0, sizeof(msgbuf));
230223
#endif
231224
#if debug_local_flag
232225
printf("Initial values sent\n");
233226
for(int i = 0; i < (sizeof(head) + sizeof(initpkt) + sizeof(monitorpkt)); i++)
234-
printf("%c", initialbuf[i]);
227+
printf("%c", msgbuf[i]);
235228
#endif
236-
free(initialbuf);
237229
while(1)
238230
{
239231
sleep(1);

0 commit comments

Comments
 (0)