Skip to content

Commit

Permalink
Missing member initialization added and Pointer check before usage added
Browse files Browse the repository at this point in the history
  • Loading branch information
HaseenaSainul committed Mar 13, 2024
1 parent b2158a3 commit d934e6b
Show file tree
Hide file tree
Showing 49 changed files with 932 additions and 306 deletions.
2 changes: 2 additions & 0 deletions DeviceIdentification/DeviceIdentification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ namespace Plugin {
}
}
#else
ASSERT(_service != nullptr);
// extract DeviceId set by Thunder
if (_service->SubSystems()->IsActive(PluginHost::ISubSystem::IDENTIFIER) == true) {

Expand All @@ -180,6 +181,7 @@ namespace Plugin {

void DeviceIdentification::Info(JsonData::DeviceIdentification::DeviceidentificationData& deviceInfo) const
{
ASSERT(_identifier != nullptr);
deviceInfo.Firmwareversion = _identifier->FirmwareVersion();
deviceInfo.Chipset = _identifier->Chipset();

Expand Down
19 changes: 14 additions & 5 deletions DeviceInfo/DeviceInfoJsonRpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,10 @@ namespace Plugin {
{
uint32_t result = Core::ERROR_NONE;
string serialNumber;
result = _deviceInfo->SerialNumber(serialNumber);
ASSERT(_deviceInfo != nullptr);
result = _deviceInfo->SerialNumber(serialNumber);

response.Serialnumber = serialNumber;
response.Serialnumber = serialNumber;
return result;
}

Expand All @@ -259,7 +260,8 @@ namespace Plugin {
uint32_t DeviceInfo::endpoint_get_modelid(ModelidData& response) const
{
string sku;
uint32_t result = _deviceInfo->Sku(sku);
ASSERT(_deviceInfo != nullptr);
uint32_t result = _deviceInfo->Sku(sku);
if (result == Core::ERROR_NONE) {
Core::EnumerateType<JsonData::DeviceInfo::ModelidData::SkuType> value(sku.c_str(), false);
if (value.IsSet()) {
Expand All @@ -279,7 +281,8 @@ namespace Plugin {
// - ERROR_GENERAL:
uint32_t DeviceInfo::endpoint_get_make(MakeData& response) const
{
string make;
string make;
ASSERT(_deviceInfo != nullptr);
uint32_t result = _deviceInfo->Make(make);
if (result == Core::ERROR_NONE) {
Core::EnumerateType<JsonData::DeviceInfo::MakeData::MakeType> value(make.c_str(), false);
Expand All @@ -300,6 +303,7 @@ namespace Plugin {
uint32_t DeviceInfo::endpoint_get_modelname(ModelnameData& response) const
{
string modelName;
ASSERT(_deviceInfo != nullptr);
uint32_t result = _deviceInfo->ModelName(modelName);

response.Model = modelName;
Expand All @@ -313,8 +317,9 @@ namespace Plugin {
uint32_t DeviceInfo::endpoint_get_modelyear(ModelyearData& response) const
{
uint16_t year;
ASSERT(_deviceInfo != nullptr);
uint32_t result = _deviceInfo->ModelYear(year);
response.Year = year;
response.Year = year;

return result;
}
Expand All @@ -326,6 +331,7 @@ namespace Plugin {
uint32_t DeviceInfo::endpoint_get_friendlyname(FriendlynameInfo& response) const
{
string name;
ASSERT(_deviceInfo != nullptr);
uint32_t result = _deviceInfo->FriendlyName(name);
response.Name = name;

Expand All @@ -339,6 +345,7 @@ namespace Plugin {
uint32_t DeviceInfo::endpoint_get_platformname(FriendlynameInfo& response) const
{
string name;
ASSERT(_deviceInfo != nullptr);
uint32_t result = _deviceInfo->PlatformName(name);
response.Name = name;

Expand All @@ -353,6 +360,7 @@ namespace Plugin {
{
string deviceType;

ASSERT(_deviceInfo != nullptr);
uint32_t result = _deviceInfo->DeviceType(deviceType);
if (result == Core::ERROR_NONE) {
Core::EnumerateType<JsonData::DeviceInfo::DevicetypeData::DevicetypeType> value(deviceType.c_str(), false);
Expand All @@ -375,6 +383,7 @@ namespace Plugin {
{
string distributorId;

ASSERT(_deviceInfo != nullptr);
uint32_t result = _deviceInfo->DistributorId(distributorId);
if (result == Core::ERROR_NONE) {
Core::EnumerateType<JsonData::DeviceInfo::DistributoridData::DistributoridType> value(distributorId.c_str(), false);
Expand Down
12 changes: 6 additions & 6 deletions DisplayInfo/DeviceSettings/Amlogic/SoC_abstraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static void getPrimaryPlane(int drm_fd, kms_ctx *kms, drmModePlane **plane)
kms_get_plane(drm_fd, kms);
cout << "Primary Plane ID : "<< kms->primary_plane_id << endl;
*plane = drmModeGetPlane(drm_fd, kms->primary_plane_id );
if(*plane)
if (*plane)
printf("fb id : %d\n", (*plane)->fb_id);
}

Expand All @@ -113,21 +113,21 @@ static void getGraphicSize(uint32_t &w, uint32_t &h)

/* Setup KMS */
kms = kms_setup(drm_fd);
if(!kms || !kms->crtc ) {
if (!kms || !kms->crtc) {
cout << "[Amlogic] kms_setup fail" << endl;
break;
}

/* Get primary buffer */
getPrimaryPlane(drm_fd, kms, &plane);
if( !plane) {
if (!plane) {
cout << "[Amlogic] fail to getPrimaryPlane" << endl;
break;
}

/* get fb */
drmModeFB *fb = drmModeGetFB(drm_fd, plane->fb_id);
while(!fb) {
while (!fb) {
getPrimaryPlane(drm_fd, kms, &plane);
fb = drmModeGetFB(drm_fd, plane->fb_id);
if (trytimes++ > 100) {
Expand All @@ -137,7 +137,7 @@ static void getGraphicSize(uint32_t &w, uint32_t &h)
}

/* Get the width and height */
if(fb) {
if (fb) {
w = fb->width;
h = fb->height;
drmModeFreeFB(fb);
Expand All @@ -146,7 +146,7 @@ static void getGraphicSize(uint32_t &w, uint32_t &h)

/* release */
/* Cleanup buffer info */
if(kms) {
if (kms) {
kms_cleanup_context(kms);
free(kms);
}
Expand Down
137 changes: 74 additions & 63 deletions DisplayInfo/DeviceSettings/Amlogic/kms.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,31 @@

void kms_setup_encoder( int fd, kms_ctx *kms )
{
for( int i = 0; i < kms->res->count_encoders; i++ ) {
if (kms != NULL && kms->res != NULL) {
for (int i = 0; i < kms->res->count_encoders; i++) {

kms->encoder = drmModeGetEncoder(fd,kms->res->encoders[i]);
kms->encoder = drmModeGetEncoder(fd,kms->res->encoders[i]);

if( !kms->encoder ) {
return;
}
if (!kms->encoder) {
return;
}

if ( kms->encoder->encoder_id == kms->connector->encoder_id ) {

kms->encoder_id = kms->encoder->encoder_id;
return;
}
if (kms->encoder->encoder_id == kms->connector->encoder_id) {

kms->encoder_id = kms->encoder->encoder_id;
return;
}

for( int j = 0; j < kms->res->count_crtcs; j++ ) {
for (int j = 0; j < kms->res->count_crtcs; j++) {

if( kms->encoder->possible_crtcs & ( 1 << j ) ) {
if (kms->encoder->possible_crtcs & (1 << j)) {

drmModeFreeEncoder( kms->encoder );
kms->encoder = drmModeGetEncoder(fd, kms->res->encoders[j]);
drmModeFreeEncoder(kms->encoder);
kms->encoder = drmModeGetEncoder(fd, kms->res->encoders[j]);

kms->encoder->crtc_id = kms->crtc_id = j;
goto exit;
kms->encoder->crtc_id = kms->crtc_id = j;
goto exit;
}
}
}
}
Expand All @@ -65,21 +66,23 @@ void kms_setup_connector( int fd, kms_ctx *kms )
int i = 0;
drmModeConnector *connector = NULL;

for( i = 0; i < kms->res->count_connectors; i++ ) {
if (kms != NULL && kms->res != NULL) {
for (i = 0; i < kms->res->count_connectors; i++) {

connector = drmModeGetConnector(fd, kms->res->connectors[i]);
if( connector ) {
connector = drmModeGetConnector(fd, kms->res->connectors[i]);
if (connector) {

if( connector->count_modes && ( connector->connection == DRM_MODE_CONNECTED ) ) {
break;
if (connector->count_modes && (connector->connection == DRM_MODE_CONNECTED)) {
break;
}
}
}
}

if ( connector ) {
if (connector) {

kms->connector = connector;
kms->connector_id = connector->connector_id;
kms->connector = connector;
kms->connector_id = connector->connector_id;
}
}

return;
Expand All @@ -88,11 +91,11 @@ void kms_setup_connector( int fd, kms_ctx *kms )

void kms_setup_crtc( int fd, kms_ctx *kms )
{
if( kms->encoder ) {
if (kms != NULL && kms->encoder) {

kms->crtc = drmModeGetCrtc(fd, kms->encoder->crtc_id);

if( kms->crtc && kms->crtc->mode_valid ) {
if (kms->crtc && kms->crtc->mode_valid) {

kms->current_info = kms->crtc->mode;
kms->crtc_id = kms->encoder->crtc_id;
Expand All @@ -107,7 +110,7 @@ kms_ctx* kms_setup( int fd )
{
kms_ctx *kms = NULL;
kms = (kms_ctx*)calloc(1,sizeof(*kms));
if( !kms )
if (!kms)
assert(0);

kms->res = drmModeGetResources(fd);
Expand All @@ -121,41 +124,47 @@ kms_ctx* kms_setup( int fd )

void kms_cleanup_context( kms_ctx *kms )
{
if( kms->connector )
drmModeFreeConnector(kms->connector);
if (kms != NULL) {
if (kms->connector) {
drmModeFreeConnector(kms->connector);
}

if( kms->encoder )
drmModeFreeEncoder(kms->encoder);
if (kms->encoder) {
drmModeFreeEncoder(kms->encoder);
}

if( kms->crtc )
drmModeFreeCrtc(kms->crtc);
if (kms->crtc) {
drmModeFreeCrtc(kms->crtc);
}

if( kms->res )
drmModeFreeResources(kms->res);
if (kms->res) {
drmModeFreeResources(kms->res);
}
}
}


uint32_t kms_get_properties(int fd, drmModeObjectProperties *props, const char *name)
{
drmModePropertyPtr property;
uint32_t i, id = 0;
if (props) {
for (i = 0; i < props->count_props; i++) {

for (i = 0; i < props->count_props; i++) {
property = drmModeGetProperty(fd, props->props[i]);
if (!strcmp(property->name, name))
id = property->prop_id;

property = drmModeGetProperty(fd, props->props[i]);
if (!strcmp(property->name, name))
id = property->prop_id;
drmModeFreeProperty(property);

drmModeFreeProperty(property);

if ( id )
return id;
if (id)
return id;
}
}
return id;
}



void kms_get_plane( int fd, kms_ctx *kms )
{
int n = 0, j = 0;
Expand All @@ -167,46 +176,48 @@ void kms_get_plane( int fd, kms_ctx *kms )

drmSetClientCap(fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);

kms->primary_plane_id = kms->overlay_plane_id = -1;
if (kms) {
kms->primary_plane_id = kms->overlay_plane_id = -1;
}

planeRes = drmModeGetPlaneResources( fd );
if ( planeRes ) {
planeRes = drmModeGetPlaneResources(fd);
if (planeRes) {

for( n= 0; n < planeRes->count_planes; ++n ) {
for (n= 0; n < planeRes->count_planes; ++n) {

plane = drmModeGetPlane( fd, planeRes->planes[n] );
plane = drmModeGetPlane(fd, planeRes->planes[n]);

if ( plane ) {
if (plane) {

props = drmModeObjectGetProperties( fd, planeRes->planes[n], DRM_MODE_OBJECT_PLANE );
if ( props ) {
props = drmModeObjectGetProperties(fd, planeRes->planes[n], DRM_MODE_OBJECT_PLANE);
if (props) {

for( j= 0; j < props->count_props; ++j ) {
for(j= 0; j < props->count_props; ++j) {

prop = drmModeGetProperty( fd, props->props[j] );
if ( prop ) {
prop = drmModeGetProperty(fd, props->props[j]);
if (prop) {

if ( !strcmp( prop->name, "type") ) {
if (!strcmp(prop->name, "type")) {

if ( ( props->prop_values[j] == DRM_PLANE_TYPE_PRIMARY ) && ( kms->primary_plane_id == -1 ) )
if ((props->prop_values[j] == DRM_PLANE_TYPE_PRIMARY) && (kms && kms->primary_plane_id == -1))
kms->primary_plane_id = planeRes->planes[n];

else if ( ( props->prop_values[j] == DRM_PLANE_TYPE_OVERLAY ) && ( kms->overlay_plane_id == -1 ) )
else if ((props->prop_values[j] == DRM_PLANE_TYPE_OVERLAY) && (kms && kms->overlay_plane_id == -1))
kms->overlay_plane_id = planeRes->planes[n];
}
}

drmModeFreeProperty( prop );
drmModeFreeProperty(prop);
}
}

drmModeFreeObjectProperties( props );
drmModeFreeObjectProperties(props);
}

drmModeFreePlane( plane );
drmModeFreePlane(plane);
}

}

drmModeFreePlaneResources( planeRes );
drmModeFreePlaneResources(planeRes);
}
Loading

0 comments on commit d934e6b

Please sign in to comment.