114 |
114 |
115 /*****************************************************************************/ |
115 /*****************************************************************************/ |
116 |
116 |
117 /** Add a new Pdo to the list. |
117 /** Add a new Pdo to the list. |
118 * |
118 * |
119 * \retval >0 Pointer to new Pdo. |
119 * \return Pointer to new Pdo, otherwise an ERR_PTR() code. |
120 * \retval NULL No memory. |
|
121 */ |
120 */ |
122 ec_pdo_t *ec_pdo_list_add_pdo( |
121 ec_pdo_t *ec_pdo_list_add_pdo( |
123 ec_pdo_list_t *pl, /**< Pdo list. */ |
122 ec_pdo_list_t *pl, /**< Pdo list. */ |
124 uint16_t index /**< Pdo index. */ |
123 uint16_t index /**< Pdo index. */ |
125 ) |
124 ) |
126 { |
125 { |
127 ec_pdo_t *pdo; |
126 ec_pdo_t *pdo; |
128 |
127 |
129 if (!(pdo = (ec_pdo_t *) kmalloc(sizeof(ec_pdo_t), GFP_KERNEL))) { |
128 if (!(pdo = (ec_pdo_t *) kmalloc(sizeof(ec_pdo_t), GFP_KERNEL))) { |
130 EC_ERR("Failed to allocate memory for Pdo.\n"); |
129 EC_ERR("Failed to allocate memory for Pdo.\n"); |
131 return NULL; |
130 return ERR_PTR(-ENOMEM); |
132 } |
131 } |
133 |
132 |
134 ec_pdo_init(pdo); |
133 ec_pdo_init(pdo); |
135 pdo->index = index; |
134 pdo->index = index; |
136 list_add_tail(&pdo->list, &pl->list); |
135 list_add_tail(&pdo->list, &pl->list); |
147 ec_pdo_list_t *pl, /**< Pdo list. */ |
146 ec_pdo_list_t *pl, /**< Pdo list. */ |
148 const ec_pdo_t *pdo /**< Pdo to add. */ |
147 const ec_pdo_t *pdo /**< Pdo to add. */ |
149 ) |
148 ) |
150 { |
149 { |
151 ec_pdo_t *mapped_pdo; |
150 ec_pdo_t *mapped_pdo; |
|
151 int ret; |
152 |
152 |
153 // Pdo already mapped? |
153 // Pdo already mapped? |
154 list_for_each_entry(mapped_pdo, &pl->list, list) { |
154 list_for_each_entry(mapped_pdo, &pl->list, list) { |
155 if (mapped_pdo->index != pdo->index) continue; |
155 if (mapped_pdo->index != pdo->index) continue; |
156 EC_ERR("Pdo 0x%04X is already mapped!\n", pdo->index); |
156 EC_ERR("Pdo 0x%04X is already mapped!\n", pdo->index); |
157 return -1; |
157 return -EEXIST; |
158 } |
158 } |
159 |
159 |
160 if (!(mapped_pdo = kmalloc(sizeof(ec_pdo_t), GFP_KERNEL))) { |
160 if (!(mapped_pdo = kmalloc(sizeof(ec_pdo_t), GFP_KERNEL))) { |
161 EC_ERR("Failed to allocate Pdo memory.\n"); |
161 EC_ERR("Failed to allocate Pdo memory.\n"); |
162 return -1; |
162 return -ENOMEM; |
163 } |
163 } |
164 |
164 |
165 if (ec_pdo_init_copy(mapped_pdo, pdo)) { |
165 ret = ec_pdo_init_copy(mapped_pdo, pdo); |
|
166 if (ret < 0) { |
166 kfree(mapped_pdo); |
167 kfree(mapped_pdo); |
167 return -1; |
168 return ret; |
168 } |
169 } |
169 |
170 |
170 list_add_tail(&mapped_pdo->list, &pl->list); |
171 list_add_tail(&mapped_pdo->list, &pl->list); |
171 return 0; |
172 return 0; |
172 } |
173 } |
181 ec_pdo_list_t *pl, /**< Pdo list. */ |
182 ec_pdo_list_t *pl, /**< Pdo list. */ |
182 const ec_pdo_list_t *other /**< Pdo list to copy from. */ |
183 const ec_pdo_list_t *other /**< Pdo list to copy from. */ |
183 ) |
184 ) |
184 { |
185 { |
185 ec_pdo_t *other_pdo; |
186 ec_pdo_t *other_pdo; |
|
187 int ret; |
186 |
188 |
187 ec_pdo_list_clear_pdos(pl); |
189 ec_pdo_list_clear_pdos(pl); |
188 |
190 |
189 // Pdo already mapped? |
191 // Pdo already mapped? |
190 list_for_each_entry(other_pdo, &other->list, list) { |
192 list_for_each_entry(other_pdo, &other->list, list) { |
191 if (ec_pdo_list_add_pdo_copy(pl, other_pdo)) |
193 ret = ec_pdo_list_add_pdo_copy(pl, other_pdo); |
192 return -1; |
194 if (ret) |
|
195 return ret; |
193 } |
196 } |
194 |
197 |
195 return 0; |
198 return 0; |
196 } |
199 } |
197 |
200 |